note 52493 deleted from function.strtr by danbrown

From: Date: Thu, 04 Mar 2010 18:22:03 +0000
Subject: note 52493 deleted from function.strtr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166678@lists.php.net to get a copy of this message
Note Submitter: Jay K ---- 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.

« previous php.notes (#166678) next »