note 97574 added to function.str-replace

From: Date: Mon, 26 Apr 2010 20:23:22 +0000
Subject: note 97574 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-168677@lists.php.net to get a copy of this message
Might be worth mentioning that a SIMPLE way to accomplish Example 2 (potential gotchas) is to simply start your "replacements" in reverse. So instead of starting from "A" and ending with "E": $search = array('A', 'B', 'C', 'D', 'E'); $replace = array('B', 'C', 'D', 'E', 'F'); // replaces A to B, B to C, C to D, D to E, E to F (makes them all F) start from "E" and end with "A": $search = array('E', 'D', 'C', 'B', 'A'); $replace = array('F', 'E', 'D', 'C', 'B'); // replaces E to F, D to E, C to D, B to C, A to B (prevents from multiple replacements of already replaced values) So basically start from the "end" and put the replacements in an order where the "replaced value" won't equal a value that exists later in the "search array". ---- Server IP: 69.147.83.197 Probable Submitter: 75.144.230.254 ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- https://master.php.net/note/edit/97574 Del: integrated -- https://master.php.net/note/delete/97574/integrated Del: useless -- https://master.php.net/note/delete/97574/useless Del: bad code -- https://master.php.net/note/delete/97574/bad+code Del: spam -- https://master.php.net/note/delete/97574/spam Del: non-english -- https://master.php.net/note/delete/97574/non-english Del: in docs -- https://master.php.net/note/delete/97574/in+docs Del: other reasons-- https://master.php.net/note/delete/97574 Reject -- https://master.php.net/note/reject/97574 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168677) next »