Re: counting lines in a file?
| From: | Matt McClanahan | Date: | Mon, 25 Sep 2000 22:53:17 +0000 |
| Subject: | Re: counting lines in a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17381@lists.php.net to get a copy of this message | ||
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