Welcome to WebmasterWorld Guest from 54.163.84.199

Forum Moderators: coopster & jatar k

php preg replace array

   
6:26 am on Nov 10, 2009 (gmt 0)

5+ Year Member



how do you replace a value with an array of values several times?
4:49 pm on Nov 10, 2009 (gmt 0)

10+ Year Member



$find_array = array('foo','bar');
$replace_array = array('moo','car');

$string = 'foo bar';
echo str_replace($find_array, $replace_array, $string);

//outputs
moo car

9:47 pm on Nov 10, 2009 (gmt 0)

5+ Year Member



everyone does replace with both find an array and the replace an array. how do you do it with just the replace an array?
10:42 pm on Nov 10, 2009 (gmt 0)

10+ Year Member



Because, the occurance of the first element in the replace array would overwrite all occurances of the find making the additional replaces irrelevant.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month