|  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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
10 + 7 = ?
Subscribe to this entry?

 [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-2023 The PHP Group
All rights reserved.
Last updated: Thu Sep 28 07:01:25 2023 UTC