Originally posted by hismightiness
<?php
$filename="myfile.txt";
$numrows=count(file($filename));
?>
this will work but it is a highly inefficient solution if you need to do anyting else with the file because you'll have to read the file twice. If you are not doing any other processing of the file then this is fine, but I am left wondering why you would need the lines and no other processing of the file. Here is how I would change it.
Originally posted by hismightiness
<?php
function getFileAndLines($filename) {
if(!file_exists($filename)) {
die("dude you can't get a file that's not there.");
}
$lines = file($filename);
array_push($lines,count($lines));
return $lines
} //end getFileAndLines
?>
but after writting this it seems a bit over kill to add the lines into the array and count will give that to you when ever you want. The only thing I was commenting on was only read the file once in a script.