0

Converting unknown symbols in url ,

like this

https://r4---sn-hgn7zn7r.c.docs.google.com/videoplayback?requiressl\u003dyes\u0026id\u003d376b916e4a3c65b1\u0026itag\u003d22\u0026source\u003dwebdrive\u0026app\u003dtexmex\u0026ip\u003d109.110.116.1\u0026ipbits\u003d8\u0026expire\u003d1456065477\u0026sparams\u003drequiressl%2Cid%2Citag%2Csource%2Cip%2Cipbits%2Cexpire\u0026signature\u003d5C06093099C3B4A7DE28AF323E2E15AC7DE5BEEE.758E1110B23CD41EA7E246DE2564ABE5368431FE\u0026key\u003dck2\u0026mm\u003d30\u0026mn\u003dsn-hgn7zn7r\u0026ms\u003dnxu\u0026mt\u003d1456050981\u0026mv\u003dm\u0026nh\u003dIgpwcjAyLm1yczAyKgkxMjcuMC4wLjE\u0026pl\u003d22

to real link, like this

https://r4---sn-hgn7zn7r.c.docs.google.com/videoplayback?requiressl=yes&id=376b916e4a3c65b1&itag=22&source=webdrive&app=texmex&ip=109.110.116.1&ipbits=8&expire=1456065477&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=5C06093099C3B4A7DE28AF323E2E15AC7DE5BEEE.758E1110B23CD41EA7E246DE2564ABE5368431FE&key=ck2&mm=30&mn=sn-hgn7zn7r&ms=nxu&mt=1456050981&mv=m&nh=IgpwcjAyLm1yczAyKgkxMjcuMC4wLjE&pl=22

i have no idea how convert it ,

i use this website to convert the link DDecode - Hex,Octal,HTML Decode

Mahmoud.ryan
  • 32
  • 1
  • 6

2 Answers2

1

In your case, you have to convert unicode escape sequences like "\uxxxx" into utf8 characters.
Use preg_repalce_callback function to replace all matched escape sequences with the respective utf8 character.
In the callback function we are using pack function which will pack the initial HEX string to binary string, then it will convert that binary order('UCS-2BE') into UTF-8 equivalent with mb-convert-encoding.

$str = "https://r4---sn-hgn7zn7r.c.docs.google.com/videoplayback?requiressl\u003dyes\u0026id\u003d376b916e4a3c65b1\u0026itag\u003d22\u0026source\u003dwebdrive\u0026app\u003dtexmex\u0026ip\u003d109.110.116.1\u0026ipbits\u003d8\u0026expire\u003d1456065477\u0026sparams\u003drequiressl%2Cid%2Citag%2Csource%2Cip%2Cipbits%2Cexpire\u0026signature\u003d5C06093099C3B4A7DE28AF323E2E15AC7DE5BEEE.758E1110B23CD41EA7E246DE2564ABE5368431FE\u0026key\u003dck2\u0026mm\u003d30\u0026mn\u003dsn-hgn7zn7r\u0026ms\u003dnxu\u0026mt\u003d1456050981\u0026mv\u003dm\u0026nh\u003dIgpwcjAyLm1yczAyKgkxMjcuMC4wLjE\u0026pl\u003d22";

$str = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) {
    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}, rawurldecode($str));

echo $str;
// the output:
https://r4---sn-hgn7zn7r.c.docs.google.com/videoplayback?requiressl=yes&id=376b916e4a3c65b1&itag=22&source=webdrive&app=texmex&ip=109.110.116.1&ipbits=8&expire=1456065477&sparams=requiressl,id,itag,source,ip,ipbits,expire&signature=5C06093099C3B4A7DE28AF323E2E15AC7DE5BEEE.758E1110B23CD41EA7E246DE2564ABE5368431FE&key=ck2&mm=30&mn=sn-hgn7zn7r&ms=nxu&mt=1456050981&mv=m&nh=IgpwcjAyLm1yczAyKgkxMjcuMC4wLjE&pl=22

http://php.net/manual/en/function.preg-replace-callback.php

RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

It appears to be "Unicode Escape Sequences for Latin 1 Characters" (see http://archive.oreilly.com/pub/a/actionscript/excerpts/as3-cookbook/appendix.html).

A quick search didn't find any native library for decoding this in PHP, but it should be straightforward to decode the characters you're most likely to encounter that need decoding (& and = specifically).

Here's a SO solution to doing it from 5 years ago: How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?

Community
  • 1
  • 1
Davis
  • 856
  • 4
  • 11