Page 1 of 1

How to read newest files only, in a text file.

Posted: Sun Jul 28, 2002 11:56 am
by Fluxcore
I have a text file that a form writes to. Then the output is printed on the screen, but the output gets to be to long on the screen. Is there a way to read the 10 newest entries only? Thanks.

Posted: Sun Jul 28, 2002 1:24 pm
by hob_goblin
ok say "file.txt" contained

Code: Select all

foo
bar
barz
foobar
foobarbarz
and i did this script:

Code: Select all

$file = file("file.txt");
$file = array_reverse($file);
$file = array_slice($file, 0, 3);
foreach($file as $data){
 echo $data;
 echo "<br /> \n";
&#125;
then it should print out:

Code: Select all

foobarbarz
foobar
barz
got the idea? look into http://www.php.net/file and http://www.php.net/array_reverse and http://www.php.net/array_slice

Posted: Sun Jul 28, 2002 2:51 pm
by Fluxcore
Thank you, worked wonderful, thanks for the fast help.

Posted: Sun Jul 28, 2002 3:50 pm
by hob_goblin
Glad to know it helped. I wasn't sure if you had information on single lines or not.