Replacing backslashes with forward slashes with str_replace() in php
PhpPhp Problem Overview
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
Php Solutions
Solution 1 - Php
you have to place double-backslash
$str = str_replace('\\', '/', $str);
Solution 2 - Php
$str = str_replace('\\', '/', $str);
Solution 3 - Php
No regex, so no need for //.
this should work:
$str = str_replace("\\", '/', $str);
You need to escape "" as well.
Solution 4 - Php
You need to escape backslash with a \
$str = str_replace ("\\", "/", $str);
Solution 5 - Php
Single quoted php string variable works.
$str = 'http://www.domain.com/data/images\flags/en.gif';
$str = str_replace('\\', '/', $str);
Solution 6 - Php
You want to replace the Backslash?
Try stripcslashes: