RE: [PHP] str_replace on words?
| From: | Mikey | Date: | Wed, 11 May 2005 17:29:13 +0000 |
| Subject: | RE: [PHP] str_replace on words? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-214957@lists.php.net to get a copy of this message | ||
> Hi there,
>
> I am trying to strip some words from a sentence. I tried it
> with str_replace like described here:
> http://www.totallyphp.co.uk/code/find_and_replace_words_in_a_t
> ext_string_using_str_replace.htm
>
> Unfortunatelly it does not work the way I want, because if I
> want to replace the word "in" all passages containing the
> characters "in" are replaced. For example Singapore.
>
> Does anybody know how to do this on just words?
>
> Thank you for any hint,
>
> Merlin
You should look into using a regular expression as these can recognise word
boundaries when matching (preg_match, preg_replace, etc).
I think this solution will apply to your other post as well.
HTH,
Mikey