php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46193 str_replace() generates unexpected results
Submitted: 2008-09-28 21:25 UTC Modified: 2008-09-29 09:17 UTC
From: muqtada at hotmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.6 OS: windows
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: muqtada at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-09-28 21:25 UTC] muqtada at hotmail dot com
Description:
------------
i tried following script
print str_replace("wwwroot/test/wp","\");
its results in wwwroot est/wp

same time fuction is working fine on other orguments like

print str_replace("wwwroot/mycode/wp","\");
its results in wwwroot\mycode\wp



Expected result:
----------------
wwwroot/test/wp


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-28 21:32 UTC] pajoye@php.net
I'm not sure what you did but the script you show can't work.

str_replace takes three arguments and you have to use "\\" and not "\".

 [2008-09-28 21:41 UTC] muqtada at hotmail dot com
oops, i am sorry, yes i know it takes three arguments, i used following script

print str_replace('\\',"/","wwwroot\test\wp2");
 [2008-09-28 21:52 UTC] tularis@php.net
It's still bogus. do an 
echo "wwwroot\test\wp2";

and you'll see why (\t is a <tab>, you need to escape it properly if you don't want to have a tab there. If you do, your replace will work as you expect it.). str_replace works correctly and as intended. The bug is in your understanding, not the engine.
 [2008-09-28 21:57 UTC] muqtada at hotmail dot com
I guess it becuase of escape sequence,
as wwwroot\test\wp has \t in it, I also tried other strings like wwwroot\nest\wp, it also produce same result
and when i put an extra slash wwwroot\\test\wp then it gives me good result
 [2008-09-28 22:10 UTC] muqtada at hotmail dot com
Ok, but when i use
echo addslashes("wwwroot\test\wp");
it still prints wwwroot est\\wp

so even if use following 
$url= addslashes("wwwroot\test\wp");
echo str_replace("\\","/",$url);

I would have put an exta slash if knew the string always :), since it is variable, i am be having problem at undersating, but i am getting my expected results using str_replace();

Thanks
 [2008-09-29 09:17 UTC] tularis@php.net
Please stop using the bugs system for these kinds of problems. that's NOT what it is for. If you need help understanding what you're doing wrong, check out the php.general mailinglist or any other of the links here: http://www.php.net/support.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 08 23:01:33 2024 UTC