Re: counting lines in a file?

From: Date: Wed, 04 Oct 2000 00:09:34 +0000
Subject: Re: counting lines in a file?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-18495@lists.php.net to get a copy of this message
Wouldn't it be easier to do: $file = "/etc/httpd/conf/httpd.conf"; $wc_return = explode(" ",wc -l $file); $lines = $wc_return[2]; This way you aren't reading the whole file into PHP just to check the number of lines, especially if some of those line are 10 million characters long... Granted it's not 100% in PHP, but it seems clean enough to me... > is your records are variable length? if not, you could use the following > logic > > sizeof(filename)/recordlength > > "Boget, Chris" wrote: > > > > $f = fopen($filename); > > > $x=0; > > > while(!feof($f)){ > > > $tmp = fgets($f,10000000); > > > $x++; > > > } > > > now $x contain the number of lines > > > > Wait a second... > > Your lines regularly have 10,000,000 characters in them? > > The only thing the above will do is tell you how many > > tens of million characters you have in the file. > > > > Chris > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#18495) next »