Replacing backslashes with forward slashes with str_replace() in php

I have the following url:

$str = "http://www.domain.com/data/images\flags/en.gif";

I'm using str_replace to try and replace backslashes with forward slashes:

$str = str_replace('/\/', '/', $str);

It doesn't seem to work, this is the result:

http://www.domain.com/data/images\flags/en.gif

you have to place double-backslash

$str = str_replace('\\', '/', $str);

$str = str_replace('\\', '/', $str);

No regex, so no need for //.

this should work:

$str = str_replace("\\", '/', $str);

You need to escape "\" as well.


You need to escape backslash with a \

  $str = str_replace ("\\", "/", $str);

Single quoted php string variable works.

$str = 'http://www.domain.com/data/images\flags/en.gif';
$str = str_replace('\\', '/', $str);