note 73378 added to function.str-replace

From: Date: Tue, 20 Feb 2007 20:11:49 +0000
Subject: note 73378 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-123610@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 65.106.184.148 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/73378 Del: integrated -- https://master.php.net/note/delete/73378/integrated Del: useless -- https://master.php.net/note/delete/73378/useless Del: bad code -- https://master.php.net/note/delete/73378/bad+code Del: spam -- https://master.php.net/note/delete/73378/spam Del: non-english -- https://master.php.net/note/delete/73378/non-english Del: in docs -- https://master.php.net/note/delete/73378/in+docs Del: other reasons-- https://master.php.net/note/delete/73378 Reject -- https://master.php.net/note/reject/73378 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123610) next »