-3

How to remove \ from links I got from scraping.

Example:

https:\\/\\/graph.facebook.com\\/v1.0\\/159463177547058\\/photos?fields=source\u00252Cname&limit=100&after=MjA4MTA5NTMyNjgyNDIy

Is there any way?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

3 Answers3

3

Try feeding it into stripslashes().

$no_slashes_url = stripslashes("https:\/\/graph.facebook.com\/v1.0\/159463177547058\/photos?fields=source\u00252Cname&limit=100&after=MjA4MTA5NTMyNjgyNDIy");
Mark
  • 639
  • 8
  • 11
2

This is an escaped sequence where special symbols are replaced by it's escape equivalent.

Usually, you can revert this by using stripslashes(). Howover, this escape sequence uses \u for UNICODE symbols which is not supported by PHP.

But you can use this little hack instead:

$raw = "https:\\/\\/graph.facebook.com\\/v1.0\\/159463177547058\\/photos?fields=source\u00252Cname&limit=100&after=MjA4MTA5NTMyNjgyNDIy";
$url = json_decode('"'.$raw.'"');

This function converts UNICODE escaped symbols into it's UTF-8 equivalents. Only because this is an URL we can trust those UNICODE escaped sequences will be safely converted to ASCII without issues, preserving the URL functionality.

Havenard
  • 27,022
  • 5
  • 36
  • 62
  • This should be the accepted answer (although the upvotes for @Mark's answer are still valid, because in a 'normal' situation that would be the one). – giorgio May 22 '14 at 14:11
1

str_replace() would be a good place to start

http://pt2.php.net/str_replace

Ian
  • 3,539
  • 4
  • 27
  • 48
  • How are you using it? – Ian May 22 '14 at 12:42
  • 1
    Keep in mind that "unescaping" is something completely different to just removing backslashes! Just think of special control characters that will break on str_replace. – ToBe May 22 '14 at 12:49