fork download
  1. <?php
  2.  
  3. $x=[
  4. 'e-mail:&#103&#107&#118'=>'',
  5. "%u041F%u0440%u0438%u0432%u0435%u0442%21%20%u041C%u0438%u0440."=>'',
  6. "http://r...content-available-to-author-only...a.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0"=>'',
  7. "%EF%F0%E8%E2%E5%F2"=>'cp1251'
  8. ];
  9.  
  10. function unescape($str,$code='') {
  11. // $str = rawurldecode($str);
  12.  
  13. preg_match_all("/%u[0-9A-F]{4}|&#x[0-9A-F]{4};?|&#\d{3}|%[0-9A-F]{2}|.+/iU",$str,$r);
  14. $ar = $r[0];
  15. foreach($ar as $k=>$v) {
  16. if(substr($v,0,2) == "%u")
  17. $ar[$k] = iconv('UCS-2',"UTF-8",pack("H4",substr($v,4,2).substr($v,2,2)));
  18. elseif(substr($v,0,3) == "&#x")
  19. $ar[$k] = iconv('UCS-2',"UTF-8",pack("H4",substr($v,5,2).substr($v,3,2)));
  20. elseif(substr($v,0,2) == "&#") {
  21. $ar[$k]=pack("n",substr($v,2));
  22. if($code && $code!="UTF-8")
  23. $ar[$k] = iconv($code,"UTF-8",$ar[$k]);
  24. } elseif(substr($v,0,1) == "%") {
  25. $ar[$k]=pack("H2",substr($v,1,2));
  26. if($code && $code!="UTF-8")
  27. $ar[$k] = iconv($code,"UTF-8",$ar[$k]);
  28. }
  29.  
  30. }
  31. return join("",$ar);
  32. }
  33.  
  34. foreach($x as $str=>$code)
  35. echo unescape($str,$code)."\n";
  36.  
Success #stdin #stdout 0.02s 24488KB
stdin
Standard input is empty
stdout
e-mail:gkv
Привет! Мир.
http://r...content-available-to-author-only...a.org/wiki/Заглавная_страница
привет