note 51010 added to function.str-replace

From: Date: Wed, 16 Mar 2005 13:36:31 +0000
Subject: note 51010 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-86534@lists.php.net to get a copy of this message
Note that when using the str_replace function it will always replace the already replaced parts in a String even if you just allow replacement of one character at a time. [php] $thecode = '453461'; for ($t=0; $t<=5; $t++){ $index = substr($thecode,$t,1); $digits = array(1, 2, 3, 4, 5, 6); $newdigits = array(4, 5, 2, 7, 8, 0); $realcode.= str_replace($digits, $newdigits, $index); } /*Would print out '782707' instead of '7827704' as it should with this construction.*/ echo $realcode; [/php] ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51010 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51010&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51010&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51010&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51010&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51010&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51010&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86534) next »