Re: counting lines in a file?

From: Date: Mon, 25 Sep 2000 23:43:46 +0000
Subject: Re: counting lines in a file?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17437@lists.php.net to get a copy of this message
On Mon, 25 Sep 2000, Matt McClanahan wrote: > On Fri, 22 Sep 2000, Michael Packer wrote: > > > I'm sure there is some slick way of doing this which is why i'm asking... > > > > what is the best way to count the number of lines in a file (ie wc -l > > file.txt) in php > > > > currently i'm just going to open file, {read a line, inc counter} until EOF, > > close file > > > > slick way??? > > Don't ask me if it's faster or more efficient, but > > $fp = fopen('filename','r'); > $file = file($fp); > $lines = count($file); > fclose($fp); > > Matt How about this, its even quicker: $fp = file("test.txt"); echo "File is: " . count($fp) . " lines long"; You don't need to fopen it if you're using file. -- James Atkinson ----------------------------------------------------------------- James Atkinson 100world Technical Developer 512-1529 West 6th Avenue phone: +1-604-637-8122 Vancouver, BC, V6J 1R1 fax: +1-604-742-1770 Canada email: james.atkinson@100world.com http://www.100world.com +---------------------------------------------------------------+ | This message may contain confidential and/or privileged | | information. If you are not the addressee or authorized to | | receive this for the addressee, you must not use, copy, | | discolse or take any action based on this message or any | | information herein. If you have received this message in | | error, please advise the sender immediately by reply e-mail | | and delete this message. Thank you for you cooperation | +---------------------------------------------------------------+

« previous php.general (#17437) next »