note 46580 added to function.preg-replace
| From: | dinah at osu1 dot php dot net | Date: | Fri, 15 Oct 2004 23:44:24 +0000 |
| Subject: | note 46580 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78622@lists.php.net to get a copy of this message | ||
this example was incorrectly provided by a user:
$string="My name is [0]";
$names=array("Bill","Bob","Joe");
$string = preg_replace("/\[(\d+)\]/",$names[(int) ${1}],$string);
echo $string;
output should be "My name is Bill"
output works with the above case only. $string = '[1]' does NOT output Bob.
these also do NOT work:
$names[${1}]
$names[\${1}]
$names[$1]
$names[\$1]
$names[\\$1]
only these seems to work:
$names[\1]
$names[\\1]
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46580
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46580&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46580&report=yes
Search -- http://master.php.net/manage/user-notes.php