note 32992 added to function.str-replace

From: Date: Fri, 13 Jun 2003 08:59:31 +0000
Subject: note 32992 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-50267@lists.php.net to get a copy of this message
Having a string for $search and an array for $replace won't work. This is mentioned on the preg_replace() page where it's described as not making sense, but not here. But one could interpret such a situation and hence implement str_replace so that a signature of (string, array, string) or even (string, array, array) would "work". The result of $search = '*'; $replace = range(1,20); $subject = '{*}'; $result = str_replace($search, $replace, $subject); could be an array of elements "{1}", "{2}", "{3}" .... In other words it would have the same effect as $search = '*'; $replace = range(1,20); $subject = '{*}'; $result = array(); foreach($replace as $r) { $result[] = str_replace($search, $r, $subject); } I leave more elaborate applications to your imagination :) The result of a str_replace(string,array,array) would therefore presumably be an array of arrays, with its dimensions indexed by the two arrays passed in. But then there's the question of which is the first dimension and which is the second. ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32992 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32992&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32992&report=yes

« previous php.notes (#50267) next »