Re: How do I read the first n lines from a file?
| From: | Hugh Danaher | Date: | Tue, 28 Aug 2001 23:47:30 +0000 |
| Subject: | Re: How do I read the first n lines from a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64918@lists.php.net to get a copy of this message | ||
If the lines terminate in "\n", I'd use fgets($fp,1000) in a loop, and loop
as many times as needed.
$fp=fopen("filename","r") or die ("couldn't open filename");
for ($count=1;$count<=10,$count++)
{
$line=fgets($fp,1000); // the 1000 represents the number of bytes to
go to unless it finds "\n" sooner.
print "$line";
}
I'm prety sure the above will work.
Hugh
----- Original Message -----
From: Jon Farmer <jonfarmer@enta.net>
To: Tauntz <tauntz@hot.ee>; <php-general@lists.php.net>
Sent: Tuesday, August 28, 2001 6:40 AM
Subject: RE: [PHP] How do I read the first n lines from a file?
> If you are on a unix box you might want to use the tail command... if you
> use exec() the output will be in an array...
>
> --
> Jon Farmer Õ?Õ?
> Systems Programmer, Entanet www.enta.net
> Tel +44 (0)1952 428969 Mob +44 (0)7968 524175
> PGP Key available, send blank email to pgpkey@bctech.co.uk
>
> -----Original Message-----
> From: Tauntz [mailto:tauntz@hot.ee]
> Sent: 28 August 2001 12:13
> To: php-general@lists.php.net
> Subject: [PHP] How do I read the first n lines from a file?
>
>
> hi !
>
> I have a simmple question :)..
>
> Lets say that I have a file called:
> list.txt
> and I want to take the first 10 lines from it & echo it to the browser ?
>
> thank you
> Tauntz@hot.ee
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>