Re: counting lines in a file?

From: Date: Tue, 03 Oct 2000 17:52:08 +0000
Subject: Re: counting lines in a file?
Groups: php.general 
Request: Send a blank email to php-general+get-18449@lists.php.net to get a copy of this message
<<$f = fopen($filename); $x=0; while(!feof($f)){ $tmp = fgets($f,10000000); $x++; } now $x contain the number of lines>> In fact, don't bother assigning the fgets to anything, unless you want an array of lines afterward stored in $tmp. If not, change that line to fgets($f, 1024); and that should work fine (I find 1k per line is reasonable if each line in the file is proceeded by a carriage-return--if it's one big block, a larger number is needed, obviously). moshe - the L http://livendirect.cjb.net

« previous php.general (#18449) next »