note 73378 deleted from function.str-replace by philip

From: Date: Mon, 26 Feb 2007 07:00:49 +0000
Subject: note 73378 deleted from function.str-replace by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123882@lists.php.net to get a copy of this message
Note Submitter: Vladimir Kornea ---- You could do this: <? $search_array = array(); array_push($search_array, 'search_string_one'); array_push($search_array, 'search_string_two'); array_push($search_array, 'search_string_three'); $replace_array = array(); array_push($replace_array, 'replace_string_one'); array_push($replace_array, 'replace_string_two'); array_push($replace_array, 'replace_string_three'); str_replace($search_array, $replace_array, $subject); ?> But rather than worrying about the order of the elements in the $search_array and $replace_array, I find it easier to do: <? $search_replace_array = array(); $search_replace_array['search_string_one'] = 'replace_string_one'; $search_replace_array['search_string_two'] = 'replace_string_two'; $search_replace_array['search_string_three'] = 'replace_string_three'; str_replace(array_keys($search_replace_array), array_values($search_replace_array), $subject); ?>

« previous php.notes (#123882) next »