Date: 09/26/00
- Next message: Lars Holm Nielsen: "RE: [PHP] Authentication: is it a good solution?"
- Previous message: Ray Richard: "[PHP] strange error"
- In reply to: Michael Packer: "[PHP] counting lines in a file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Lars Holm Nielsen: "RE: [PHP] Authentication: is it a good solution?"
- Previous message: Ray Richard: "[PHP] strange error"
- In reply to: Michael Packer: "[PHP] counting lines in a file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

