php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8597 problem in str_replace
Submitted: 2001-01-08 10:56 UTC Modified: 2001-01-08 11:01 UTC
From: jeff at procata dot com Assigned:
Status: Closed Package: *Function Specific
PHP Version: 4.0.2 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jeff at procata dot com
New email:
PHP Version: OS:

 

 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-08 11:01 UTC] cynic@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 20:01:29 2024 UTC