RE: [PHP] Count lines or chars

From: Date: Fri, 17 Oct 2003 10:58:32 +0000
Subject: RE: [PHP] Count lines or chars
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-166444@lists.php.net to get a copy of this message
I guess you could do something like : <?php function countLines($filename) { if(file_exists($filename)) { $linecount=0; $fs = file($filename); while (list ($linenum, $linec) = each($fs)) { $linecount++; } return $linecount; } } $local_file = "/path/to/testfile.txt"; $lines = countLines($local_file); ?> That would count all the lines in the file. /Morten -----Original Message----- From: Markus [mailto:heugi@gmx.ch] Sent: 17. oktober 2003 11:25 To: php-general@lists.php.net Subject: [PHP] Count lines or chars Hi PHP-gurus :-) I'd like to count the lines within a file and store the result within a variable. Every line begins with the char %. Would it be easier to count these chars and how could I do that? Thanks for your help. markus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#166444) next »