|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50570 str_replace doesn't work with URL replacement
Submitted: 2009-12-24 15:57 UTC Modified: 2009-12-24 16:12 UTC
From: julijan dot andjelic at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.1 OS: Linux Mint 7 (2.6.28-17-generic)
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.
Block user comment
Status: Assign to:
Bug Type:
From: julijan dot andjelic at gmail dot com
New email:
PHP Version: OS:


 [2009-12-24 15:57 UTC] julijan dot andjelic at gmail dot com
When using str_replace with 2 arrays and 1 of them contains URL-s the result gets messed up. I provided a code snippet which shows it.

Reproduce code:

$str='I love a b c';


echo str_replace($array0, $array1, $str);


Expected result:
I love

Actual result:
I love http://www.example. http://www.example.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-24 16:12 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Givenyourcode it will take the string

$str=\'I love a b c\';

And then replace \'a\' with \'\' this gives

$str=\'I love b c\';

then it will replace \'b\' with \'\' so the result is 

$str=\'I love c\';

Finally it will replace \'c\' with, mind that both URLs include a \'c\' in \'.com\' that will be replaced, too.

so the result is

I love http://www.example. http://www.example.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 15:01:29 2024 UTC