I'm looking for how to remove those "\"
from this url
"https:\/\/pp.userapi.com\/c523219\/u213324802\/video\/l_7325c886.jpg"
using php.
I try it this way:
<?php
$url = 'https:\/\/pp.userapi.com\/c523219\/u213324802\/video\/l_7325c886.jpg';
urldecode($url);
echo $url;
?>
It still doesn't work. I'm looking for an idea.
You could apply first
FILTER_SANITIZE_URL
, this function removes illegal characters in yoururl
, in order to achieve greater security.The second step would be to apply the str_replace function to it, already mentioned, since the backslash is not illegal in a
url
.$string = str_replace('\\', '', $string);
In particular, if you want to match a backslash, type
\\
.Manual escape sequences .
A possible example:
Result :
https://pp.userapi.com/c523219/u213324802/video/l_7325c886.jpg
The function you're looking for is
str_replace
, which allows you to replace all occurrences of a string in a PHP string.In the first parameter we will indicate the string to search for within the
string
, in the second parameter the string by which it will be replaced, which in this case will be empty, and in the third parameter the onestring
in which we want to do the replacement.Example:
Result:
Note : If you notice, I use double
\\
since the backslash is used to escape special characters and, therefore, if we want to use that backslash inside astring
we must escape it using another backslash.