Original string: http://www.qdta.cn/xxw/xxInfo.asp?xxlx= Travel Hot News &id=12939
Want to convert to: http://www.qdta.cn/xxw/xxInfo.asp?xxlx= Travel Hot News &id=12939
what function do you use?
Reply to discussion (solution)
function Unescape ($str) { $str = Rawurldecode ($STR); Preg_match_all ("/(?:%u.{4}) |& #x. {4};|&#\d+;|.+/u", $str, $r); $ar = $r [0];p Rint_r ($ar); foreach ($ar as $k + $v) { if (substr ($v, 0,2) = = "%u") $ar [$k] = Iconv ("UCS-2", "GB2312", Pack ("H4", substr ($v,- 4))); ElseIf (substr ($v, 0,3) = = "& #x") $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("H4", substr ($v, 3,-1))); ElseIf (substr ($v, 0,2) = = "I") {echo substr ($v, 2,-1). "
"; $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("n", substr ($v, 2,-1))); } } return join ("", $ar);}
function Unescape ($str) { $str = Rawurldecode ($STR); Preg_match_all ("/(?:%u.{4}) |& #x. {4};|&#\d+;|.+/u", $str, $r); $ar = $r [0];p Rint_r ($ar); foreach ($ar as $k + $v) { if (substr ($v, 0,2) = = "%u") $ar [$k] = Iconv ("UCS-2", "GB2312", Pack ("H4", substr ($v,- 4))); ElseIf (substr ($v, 0,3) = = "& #x") $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("H4", substr ($v, 3,-1))); ElseIf (substr ($v, 0,2) = = "I") {echo substr ($v, 2,-1). "
"; $ar [$k] = Iconv ("UCS-2", "UTF-8", Pack ("n", substr ($v, 2,-1))); } } return join ("", $ar);}
Originally to write their own functions ah. Just do not understand is, why some want to convert into utf-8 format? I am GBK, output, is garbled, I changed the utf-8 to GBK output normal Chinese
There is a way, directly with JS good, such as
There is a way, directly with JS good, such as
Thank you, but this part needs to be handled by PHP.