|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-01-08 10:56 UTC] jeff at procata dot com
The following code:
$key = "test";
echo str_replace("{$key}", "Replaced", "abc {test} xyz");
produces incorrect output:
abc {Replaced} xyz
where the equivelant code:
echo str_replace("{test}", "Replaced", "abc {test} xyz");
produces the correct output:
abc Replaced xyz
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 01:00:01 2025 UTC |
this, though it may not be deemed as the most intuitive behavior, is the intended one. $a = array( 'aa' , 'bb' , 'cc' ) ; echo str_replace("{$a[1]}", "Replaced", "abc {aa} xyz"); will produce "abc {Replaced} xyz", whereas echo str_replace("$a[1]", "Replaced", "abc {aa} xyz"); would produce a parse error. escape the braces.