Afficher un message
Vieux 12/09/2007, 21h07   #1
Wolf
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] Getting line count of a text file

Novel approach... But mine's less typing.

never thought of using awk for it though. Good one!

---- bruce <bedouglas@earthlink.net> wrote:
> hey...
>
> if you're going to do the system approach, go ahead and use awk/cut...
>
> wc -l foo.txt | awk -F' ' '{print $1}'
>
> should work assuming you're on linux.....
>
>
>
> -----Original Message-----
> From: mike [mailto:mike503@gmail.com]
> Sent: Wednesday, September 12, 2007 12:46 PM
> To: Frank J. Schima
> Cc: php-general@lists.php.net
> Subject: Re: [php] Getting line count of a text file
>
>
> On 9/12/07, Frank J. Schima <fjs@foraker.com> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

  Réponse avec citation
 
Page generated in 0,05079 seconds with 9 queries