Re: counting lines in a file?
| From: | Andreas Pour | Date: | Wed, 27 Sep 2000 01:19:44 +0000 |
| Subject: | Re: counting lines in a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17661@lists.php.net to get a copy of this message | ||
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???
Hmm, as I favor using tools that have been built already:
if (ereg("^[[:blank:]]*([0-9]+) ",
wc -l $file, $m))
echo "lines = '$m[1]'\n";
else
echo "file '$file' not found.\n";
This can be easily modified to count words and characters as well.
Ciao,
Andreas Pour
http://www.kde.com/ : Everything KDE
http://apps.kde.com/: The Latest in KDE Applications