Re: feature request
| From: | Stig S. Bakken | Date: | Wed, 24 Apr 2002 20:29:34 +0000 |
| Subject: | Re: feature request | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-83278@lists.php.net to get a copy of this message | ||
$wc = strlen(preg_replace('/\W*\w*/', 'x', file_get_contents($file));
Look, no arrays! :-)
- Stig
On Wed, 2002-04-24 at 20:20, Nikolai Devereaux wrote:
> It would be great if there was a function in the filesystem family similar
> to the unix command "wc". It'd be nice to not have to write simple wrappers
> around system calls or creating arrays to get the number of words or lines
> in a file.
>
> For example, to get the number of lines in a file, I have to do this:
>
> // bash specific solution
> function lines($filename)
> {
> $wc =
bash -c 'wc -l $filename 2>&1';
> return (preg_match("|^\s+(\d+)\s+$filename\s*$|", $wc, $matches)?
> $matches[1] : 0;
> }
>
> or this:
> // generic solution (w/o error checks):
> function lines($filename)
> {
> return count(file($filename));
> }
>
>
> Take care,
>
> Nik
>
>
>
> --
> PHP Development Mailing List <http://www.php.net/>
> To unsubscribe, visit: http://www.php.net/unsub.php