note 46661 added to function.str-replace

From: Date: Tue, 19 Oct 2004 16:13:53 +0000
Subject: note 46661 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-78767@lists.php.net to get a copy of this message
If you have got an array like <?php $array = array( 'Peter' => 'Thomas (old name: Peter)', 'Anne' => 'Deborah (old name: Anne)', 'Julia' => 'Maria (old name: Julia)', 'Jona' => 'Joseph (old name: Jona)' ); ?> And you want to replace Peter with Thomas, Anne with Deborah and so on, you can use: <?php $string = 'Julia loves Peter but he loves Anne and Jona loves Julia'; $string = str_replace(array_keys($array), $array, $string); // output: echo $string; ?> It works fine. Have fun ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46661 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46661&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46661&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78767) next »