Afficher un message
Vieux 12/09/2007, 21h40   #6
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Getting line count of a text file

Frank J. Schima wrote:
> Hi all,
>
>
> In PHP 5, I'm counting the number of lines in a text file using the
> following code:
> $myfile = file ( '/path/to/myfile.txt');
> $count = count ($myfile);
>
> However, sometimes it fails with the following error:
> PHP Fatal error: Allowed memory size of xxxx bytes exhausted (tried
> to allocate 35 bytes) in /path/to/myprogram.php on line 16
>
> Line 16 is the first line above.
>
> I'm sure there is a better - more memory efficient - way to do this. Any
> suggestions?
>
>
> Thanks!
> Frank Schima
> Foraker Design
> <http://www.foraker.com>
>
>
>


echo intval(str_replace(' '.$file, '', trim(system('wc -l '.$file))));

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
  Réponse avec citation
 
Page generated in 0,05210 seconds with 9 queries