----- Original Message -----
From: "René Fournier" <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 1:52 PM
Subject: [PHP] str_replace() problem

> 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,

You might be able to be more precise using ereg_replace().  But I donot know
the regular expression to make it happen.  Or if your situation allows it
you can hack it by appending a single space on the end of each input.
Either way what you need to do is give the script more information about
exactly what you want to replace.

echo str_replace("Blue ", "Red ", $paragraph);


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to