Re: str_replace on words with an array
| From: | Stut | Date: | Sun, 29 Oct 2006 23:00:14 +0000 |
| Subject: | Re: str_replace on words with an array | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-243849@lists.php.net to get a copy of this message | ||
Dotan Cohen wrote:
> Thanks all for the heads up with the str_replace not working with
> regexes. Duh! I've switched to preg_replace, but still no luck. (nor
> skill, on my part)
>
> I'm trying to use array_walk to go through the array and deliminate
> each item with /b so that the preg_replace function will know to only
> operate on whole words, but I just can't seem to get it. I am of
> course Ring TFM and Sing THW but with no luck. A push (link to TFA or
> tutorial, whatever) would be most appreciated.
IMHO, unless you're going to be doing a lot with each element of the
array it's easier to do it without using array_walk.
foreach ($arr as $key => $val)
$arr[$key] = "\\b".$val."\\b";
-Stut