Re: one pattern, one string, multiple results
| From: | _lallous | Date: | Wed, 26 Sep 2001 08:30:55 +0000 |
| Subject: | Re: one pattern, one string, multiple results | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-68822@lists.php.net to get a copy of this message | ||
try this!
I don't know how effective is preg_replace w/ huge memory contents....but
this should work fine!
$mem = "an arc is an archer, arc but what about marc and darcy?";
$match = "arc";
$count = 0;
preg_replace("/\b$match\b/ie", "\$count++;", $mem);
echo $count;
"Richard Baskett" <rick@baskettcase.com> wrote in message
news:B7D6CB46.39A9%rick@baskettcase.com...
> I just can not seem to figure this out.
>
> If i have a pattern 'arc' and I want to search the string:
> "an arc is an archer, but what about marc and darcy?"
>
> How can I find out how many occurances of arc is within that string? I
know
> I can do an explode and then compare it, but when you have huge amounts of
> text... is this the best way? Or is there something better? Any help
would
> be great I have been struggling with this for awhile, since I really do
not
> want to explode, pun intended :)
>
> Rick
>