str_replace() problem
| From: | René Fournier | Date: | Mon, 31 Mar 2003 20:52:32 +0000 |
| Subject: | str_replace() problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-141737@lists.php.net to get a copy of this message | ||
I am performing a str_replace() on a large string, and everything works fine, except that two of the elements I'm searching for (and replacing) have the same first letters. To keep it the issue clear, here's a simple example of what I'm talking about:
Blue
Blueberry
Now, if I use:
str_replace("Blue","Red",$paragraph);
str_replace("Blueberry","Strawberry",$paragraph);
...all occurrences of Blue—including Blueberry—will be replaced with Red. The result will be something like:
Red
Redberry
...But what I want is...
Red
Strawberry
I need str_replace to somehow only search for a complete occurrence of each item. How do I do that? I've read the docs, and I just can't see any examples.
Thanks.
...Rene
---
René Fournier,
rene@smartslitters.com
Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228
www.smartslitters.com
SmartSlitters International
#33, 1339 - 40th Ave NE
Calgary AB T2E 8N6
Canada