#37099 [Opn->Bgs]: str_replace with arrays - weird behaviour

From: Date: Sun, 16 Apr 2006 19:03:15 +0000
Subject: #37099 [Opn->Bgs]: str_replace with arrays - weird behaviour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-95866@lists.php.net to get a copy of this message
ID: 37099 Updated by: tony2001@php.net Reported By: admin at ifyouwantblood dot de -Status: Open +Status: Bogus Bug Type: Strings related Operating System: Linux AND windows PHP Version: 5.1.2 New Comment: The problem is that both of your arrays contain the same characters. So the first str_replace() changes 'e' to 't' and then changes it back when it reaches 't' in the $replace_s array. No bug here, just a user error. Previous Comments: ------------------------------------------------------------------------ [2006-04-16 18:35:51] admin at ifyouwantblood dot de Description: ------------ str_replace does not replace all array values with the associated array replace. Reproduce code: --------------- <?php $string = "test"; test($string); function test($datei) { $search_s=range('a','z'); $replace_s=range('z','a'); $code = str_replace($search_s, $replace_s, $datei); echo $code."\n"; $decode = str_replace($replace_s, $search_s, $code); echo $decode; } ?> Expected result: ---------------- gvhg test Actual result: -------------- gehg tvst ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37099&edit=1

« previous php.bugs (#95866) next »