Reading a file backwards in PHP
February 28th, 2008This morning I needed to read from a file line by line from the bottom. In PHP. Perl, of course, has a module to do this. A quick view source decided that I didn’t want to get into file seeks before breakfast. Very happy with my solution:
$file = popen("tac $filename",'r');
while ($line = fgets($file)) {
echo $line;
}
Thanks for this post, came very handy.
Great, very handy indeed
excellent solution … thx a lot!