Other than iterating through each line and incrementing a counter (seems too resource-intensive), how can I find out how many lines are in a certain file?
Printable View
Other than iterating through each line and incrementing a counter (seems too resource-intensive), how can I find out how many lines are in a certain file?
Or something to that extent.Code:$file = file('yourfile');
$x = count($file);
echo $x . ' lines in the file.'
Cool :)
BTW...
...can be replaced with...PHP Code:echo $x . ' lines in the file.'
PHP Code:echo "$x lines in the file."
ah, nice to know. :)
could probably be replace with:Code://I should use the php tags, huh?
$file = file('yourfile');
$x = count($file);
echo $x . ' lines in the file.'
Althought I haven't tried itCode:echo count(file('yourfile')) . ' lines in the file.'
Probably could, very C++/Java-like if it works :)
FYI, just tried it. Works like a charm. :)