How to read newest files only, in a text file.
Moderator: General Moderators
How to read newest files only, in a text file.
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.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
ok say "file.txt" contained
and i did this script:
then it should print out:
got the idea? look into http://www.php.net/file and http://www.php.net/array_reverse and http://www.php.net/array_slice
Code: Select all
foo
bar
barz
foobar
foobarbarzCode: 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";
}Code: Select all
foobarbarz
foobar
barz- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact: