There is a small discussion of the problem, and it is not mentioned how to refer to the "one line" (by number, by some value inside it, etc.), so below is just a hunch about what you want.
If you are not averse to using an object (perhaps it may be a "too high level") and want to refer to a string by offset, then SplFileObject (available since PHP 5.1.0). See the following basic example:
$file = new SplFileObject('myreallyhugefile.dat'); $file->seek(12345689); // seek to line 123456790 echo $file->current(); // or simply, echo $file
This particular ( seek ) method requires scanning through a file in turn. However, if, as you say, all the lines are the same length, you can use fseek instead to get where you want to go much faster.
$line_length = 1024; // each line is 1 KB line $file->fseek($line_length * 1234567); // seek lots of bytes echo $file->current(); // echo line 1234568
salathe
source share