> Any ideas on how I can print the lines of my file in reverse order,
> then?  Does fgets() always process from the beginning of the file even
> if you open the file with the pointer at the end?  I tried to get the
> line count of the file and go through each line of the file backwards
> but that doesn't seem to work, so either it's impossible or I'm going
> about it the wrong way.  Here's the code:
> 
> $fh = fopen("data.txt", "a+") or die("Could not open file");
> $line_num = 0;
> while (! feof($fh)) {
> if ($line = fgets($fh, 1048576)) {
> $line_num++;
> }
> }
> while ($line_num != 0)) {
> if ($line = fgets($fh, 1048576)) {
> print $line;
> $line_num--;
> }
> }

$file = file('data.txt');
$rev_file = array_reverse($file);
foreach($rev_file as $line)
{ echo $line; }

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to