Re: str_replace and arrays

From: Date: Thu, 06 Sep 2001 07:51:34 +0000
Subject: Re: str_replace and arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66166@lists.php.net to get a copy of this message
<Original message> From: Gerard Samuel <trini0@optonline.net> Date: Thu, Sep 06, 2001 at 01:10:15AM -0400 Message-ID: <3B970537.3040508@optonline.net> Subject: [PHP] str_replace and arrays > Hey all. Im trying to reduce some lines of code that has muliple lines > of str_replace. I figure lets try using arrays but its not working. > E.g. I have about 15-20 lines like this. > $message = str_replace(":D", "<IMG > SRC=\"images/forum/icons/icon_biggrin.gif\">", $message); > > Im trying > $path = "images/forum/icons/"; > $one = array(":D",":)"); > $two = array("$path"."icon_biggrin.gif", > "$path"."icon_smile.gif"); > message = str_replace($one, $two, $message); > > do you see anything wrong.... </Original message> <Reply> Well... you forgot the $ sign for message at the last line, it should be $message= io message= Because the rest of the construction should just work. Check out my simple example below. You haven't said what goes wrong exactly, btw. --- PHP example --- <?php $txt = "And now :D some :-) smiley =( kind of ;) thing."; $match = array (":D", ":-)", "=(", ";)"); $replace = array ("1", "2", "3", "4"); print str_replace($match, $replace, $txt); ?> --- End of PHP example --- </Reply> -- * R&zE: -- »»»»»»»»»»»»»»»»»»»»»»»» -- Renze Munnik -- DataLink BV -- -- E: renze@datalink.nl -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- ««««««««««««««««««««««««

« previous php.general (#66166) next »