php read big file line by line

Solutions on MaxInterview for php read big file line by line by the best coders in the world

showing results for - "php read big file line by line"
Alejandro
22 Apr 2019
1if ($file = fopen("file.txt", "r")) {
2    while(!feof($file)) {
3        $line = fgets($file);
4        # do same stuff with the $line
5    }
6    fclose($file);
7}
8
Lara
12 Feb 2020
1$handle = fopen("inputfile.txt", "r");
2if ($handle) {
3    while (($line = fgets($handle)) !== false) {
4        // process the line read.
5    }
6
7    fclose($handle);
8} else {
9    // error opening the file.
10} 
11