RE: [PHP] str_replace() problem

From: Date: Mon, 31 Mar 2003 21:28:00 +0000
Subject: RE: [PHP] str_replace() problem
Groups: php.general 
Request: Send a blank email to php-general+get-141743@lists.php.net to get a copy of this message
You could replace the longer one, "Blueberry", first. Then, the only remaining occurrences of "Blue" will be ones that you really want. Kirk > 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

« previous php.general (#141743) next »