Re: How do I read the first n lines from a file?

From: Date: Tue, 28 Aug 2001 13:17:32 +0000
Subject: Re: How do I read the first n lines from a file?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-64784@lists.php.net to get a copy of this message
You might be better off using the file() function which reads a file into an array, then you can use the indexes to get whatever lines you want http://www.php.net/manual/en/function.file.php Data Driven Design 1506 Tuscaloosa Ave Holly Hill, Florida 32117 http://www.datadrivendesign.com Phone: (386) 226-8979 Websites That WORK For You ----- Original Message ----- From: "Tauntz" <tauntz@hot.ee> To: "php" <php-general@lists.php.net> Sent: Tuesday, August 28, 2001 7:59 AM Subject: Re: [PHP] How do I read the first n lines from a file? > hey.. thank you.. > but is it possible to read the last lets say 10 lines from a file ? > > > ----- Original Message ----- > From: "Niklas Lampén" <niklas.lampen@publico.fi> > To: "Tauntz" <tauntz@hot.ee>; "Php-General" > <php-general@lists.php.net> > Sent: Tuesday, August 28, 2001 3:28 PM > Subject: RE: [PHP] How do I read the first n lines from a file? > > > > You can do this: > > > > $i = 0; > > $fp = fopen("list.txt", "r"); > > while (!feof($fp) && $i < 10) { > > $i++; > > $Text = fgets($fp, 4096); // Reads first 4096 characters from a row. > > print "$Text<br>\n"; > > }; > > > > > > Niklas > > > > -----Original Message----- > > From: Tauntz [mailto:tauntz@hot.ee] > > Sent: 28. elokuuta 2001 14: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 > >

« previous php.general (#64784) next »