note 44909 deleted from function.str-replace by bjori

From: Date: Sun, 26 Mar 2006 22:26:52 +0000
Subject: note 44909 deleted from function.str-replace by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106681@lists.php.net to get a copy of this message
Note Submitter: jschultz at youritdepot dot com ---- Instead of using function str_replace_clean() posted by Jeroen use strtr(). Here is the problem str_replace_clean() fixes: $search = array("one", "two", "three"); $replace = array("two", "three", "one"); $subject = "one two three"; str_replace($search, $replace, $subject); Output: "one one one". str_replace_clean($search, $replace, $subject); Output: "three two one". Instead use strtr() as so: $trans = array( "one" => "two", "two" => "three", "three" => "one", ); strtr($subject, $trans); Output: "three two one". Hope this helps someone. I used it to replace emoticon codes :) with image tags, and it works great

« previous php.notes (#106681) next »