RE: [PHP-GENERAL] Reversing the order of a text file

From: Date: Wed, 31 May 2000 17:23:16 +0000
Subject: RE: [PHP-GENERAL] Reversing the order of a text file
Groups: php.general 
Request: Send a blank email to php-general+get-740@lists.php.net to get a copy of this message
> I need to sort it backwards... reverseing the order > of the lines in the file. currently i have: > <? > $fp=Fopen("file.txt","r"); > while (!feof($fp)) { > $buffer = fgets($fp, 4096); > echo nl2br($buffer); > } > ?> > And this reads the file into the page nicely but i > want the last line first ect? The way I would do is it something like this (pseudo-code): <? exec( "cat $file", $array ); rsort( $array ); while( list( $key, $val ) = each( $array )) { echo "$val<br>\n"; } ?> Something along those lines should do it... Chris

« previous php.general (#740) next »