Re: Counting Lines
| From: | James | Date: | Mon, 12 May 2003 10:00:45 +0000 |
| Subject: | Re: Counting Lines | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147279@lists.php.net to get a copy of this message | ||
$doc = file("doc.txt");
$myLines = count($doc);
sizeof() is an alias of count();
The idea behind this is to read the file. The file() functions reads it
into an array exploding the file with the \n (new line) syntax. You can then
count the number of lines.
If you want to use fopen,
$fp = fopen("doc.txt", "r");
while (!feof($fp)){
$contents = fread($fp, 4096);
}
fclose($contents);
$contents = explode("\n", $contents);
$myLines = count($contents);
Remember to put in error checking - this is important. If it's local to
your machine use the full path from the server root as its faster than
grabbing it by a url.
If you want a lot of file info and fancy using the linux command "wc" try
this:
$lines =explode(" ",shell_exec("wc -l -m -c -L -w index.php"));
foreach ($lines as $line){
if ($line){
echo "$line\n";
}
}
jimbob
"Aris Santillan" <aris@femalenetwork.com> wrote in message
news:831411C4CBD37C4A91DBEC9B98A64C8B6C42AB@spmail.summitmedia.com.ph...
Hi Guys!
im new to php
i want to count the # of line of
the certain document and forward
the value to a variable? how can i do it?
thanks