Hi how can i start reading a file at specific line number. I want to start reading this file at line 20 for example Thanks for your help Here is my code $fh = fopen($myFile, 'r'); while ((feof ($fh) === false) ) { $theData = fgets($fh); echo $theData; } fclose($fp);
Well, you can't just skip 20 lines forward. It's a sequential read of the file not random access. So all you can do is quickly skip the first 20 lines by ignoring them... $fh = fopen($myFile, 'r'); while ((feof ($fh) === false) ) { $i=1; while ((feof ($fh) === false) && $i<20 ) { fgets($fh); $i++; } $theData = fgets($fh); echo $theData; } fclose($fh); PHP:
$f = file_get_contents('file'); $lines = explode("\r\n",$f); for ($k=19; $k<=count($lines); $k++) { // maybe? } PHP: Would be better for random reading, not always have to skip this way.