I am working on reading a file in php. I need to read specific lines of a file.
I used this code:
fseek($file_handle,$start);
while (!feof($file_handle))
{
$line = fgets($file_handle);
$lineArray .= $line."LINE_SEPARATOR";
processLine($lineArray, $linecount, $logger, $xmlReply);
$counter++;
}
fclose($file_handle);
However, I realized that it fseek()takes the number of bytes, not the line number.
Does PHP have another function that bases its pointer on line numbers?
Or do I need to read the file every time from the very beginning and have a counter until the number of the desired line is read?
I'm looking for an efficient algorithm, stepping over 500-1000 Kbytes of files to get the desired line seems inefficient.
source
share