php3-list | 199901
Date: 01/29/99
- Next message: Noor Dawod: "Re: [PHP3] How to cache PHP pages? (2nd try)"
- Previous message: A93Shadow <email protected>: "[PHP3] Publishing Company For Sale?"
- In reply to: Jordan B. Baker: "Re: [PHP3] solution needed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Jordan B. Baker" wrote:
>
> On Thu, 28 Jan 1999, Christopher Allen wrote:
>
> > I have a file of random text in which I would like to output the last five
> > lines only. My problem is how do I postion to read only from that point to
> > EOF?? Perhaps I am missing something which might be apparent to someone
> > else in the list?
>
> If you're using UNIX and portability is not issue you can try the tail
> command.
>
> If not you might want to take a look at the tail code to see what it does.
>
> How about reading backwards in a file until you've counted 5 newlines?
>
> Just random thoughts. :)
>
Just off the top of my head. :)
You could use the file() command to read the entire file into an array
line by line, and then grab only the last five entries (lines) from the
file for output. :)
$foo = file( "somefile.txt" );
$size = sizeof( $foo );
$cursor = $size - 5;
while( $cursor < $size ) {
echo $foo[$cursor];
$cursor++;
}
OR
while( $cursor < $size ) {
$output[] = $foo[$cursor];
$cursor++;
}
OR
$output = "";
while( $cursor < $size ) {
$output .= $foo[$cursor];
$cursor++;
}
Or.. something like that. The idea seems sound though. But what do I
know.. it's late, and I felt like tackling a brain teaser.. :)
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>
- Next message: Noor Dawod: "Re: [PHP3] How to cache PHP pages? (2nd try)"
- Previous message: A93Shadow <email protected>: "[PHP3] Publishing Company For Sale?"
- In reply to: Jordan B. Baker: "Re: [PHP3] solution needed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

