note 52493 added to function.strtr

From: Date: Tue, 03 May 2005 16:22:55 +0000
Subject: note 52493 added to function.strtr
Groups: php.notes 
Request: Send a blank email to php-notes+get-88908@lists.php.net to get a copy of this message
Several people have suggested using str_replace instead of strtr... Here is why that will not always work.... <? $string = "This is a BIG test with SMALL RESULT\n"; $repl = array('BIG' => 'SMALL', 'SMALL' => 'BIG'); echo str_replace(array_keys($repl), array_values($repl), $string); echo strtr($string, $repl); ?> Results in: This is a BIG test with BIG RESULT This is a SMALL test with BIG RESULT Notice that str_replace will replace previous replacements and strtr will not. ---- Manual Page -- http://www.php.net/manual/en/function.strtr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52493 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52493&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52493&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52493&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52493&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52493&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52493&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88908) next »