Re: including() only given amount of lines

From: Date: Sat, 10 May 2003 17:10:59 +0000
Subject: Re: including() only given amount of lines
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147128@lists.php.net to get a copy of this message
Try something like this. if( $fd = fopen ($filename, "r") ) while (!feof ($fd)) { $buffer[] = fgets($fd, 4096); if( count($buffer) > 50 ) array_shift($buffer); } fclose ($fd); } as you read the file, it will create an array. As it loops and creates the array. if it reaches a count of greater then 50 then as it loops it will drop off the first key=>value pair, adjust the key numbers and continue on. This way your array will never be larger then a count of 50 Jim Lucas ----- Original Message ----- From: <iliketheworld@gmx.ch> To: <php-general@lists.php.net> Sent: Saturday, May 10, 2003 9:45 AM Subject: Re: [PHP] including() only given amount of lines > am 10.05.2003 15:44 Uhr schrieb Jason Wong unter php-general@gremlins.biz: > > > On Saturday 10 May 2003 19:53, iliketheworld@gmx.ch wrote: > > > >> 1. i would like to include only a given amount (the first 50) lines of a > >> text file. i think they should be included using fgets() or fread() instead > >> of include() but i dont know how. > >> > >> 2. besides that i need to include the laste 50 lines of a text file -- in > >> reversed order! > > > > The easiest way would be to use file() and the array manipulation functions. > > yes, but isn't a 500+ line file a bit heavy to read into an array? i thought > this may cause massive slow down -- isn't it? > > can someone help me with this? > > > thanks for your effort! > > philipp > http://www.ipdraw.org/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#147128) next »