note 44909 added to function.str-replace

From: Date: Thu, 19 Aug 2004 21:40:13 +0000
Subject: note 44909 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-79911@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44909 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44909&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44909&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79911) next »