Re: Getting line count of a text file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/12/07, Frank J. Schima <fjs@xxxxxxxxxxx> wrote:
> 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?

it's sloppy but you could use system("wc -l $file") and grab the first
part before the space (doesn't seem to be an option to NOT display the
filename again)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux