I want to replace all forward slashes /
in my URL with \/
.
For example, this URL
http://media3.giphy.com/media/8etoa2PC4Mgx2/200w.mp4
should be changed to
http:\/\/media3.giphy.com\/media\/8etoa2PC4Mgx2\/200w.mp4
I have tried to do this with this code:
<?php
$filename="http://media3.giphy.com/media/8etoa2PC4Mgx2/200w.mp4"
$filename=str_replace("\//","\/","$filename");
echo $filename:
?>
but it is not working. How can I do this?
$filename = str_replace( "/", "\/", $filename );
Do not wrap$filename
in quotes, because it's a variable. If you remove the quotes in third str_replace
parameter, it should works.
Edit: You need to escape backslash ( \
) only, because it has special meaning in PHP.
To specify a literal single quote, escape it with a backslash (). To specify a literal backslash, double it (\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as or , will be output literally as specified rather than having any special meaning.
at end not :
(colon) it is ;
(semicolon) and not quotes "
for $filename
<?php
$filename="http://media3.giphy.com/media/8etoa2PC4Mgx2/200w.mp4";
$filename=str_replace("/","\/",$filename);
echo $filename;
?>