note 32992 deleted from function.str-replace by philip

From: Date: Wed, 07 Oct 2009 08:06:30 +0000
Subject: note 32992 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-161465@lists.php.net to get a copy of this message
Note Submitter: ---- 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 <?php $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 <?php $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.

« previous php.notes (#161465) next »