请问php如何把尀u4e2d尀u56fd 和尀u534e尀u5357 转换成中文

如何把中文互换上面的编码..还有上面的是什么意思.
2024-12-30 17:07:32
推荐回答(3个)
回答1:

这是unicode编码,
\u4e2d\u56fd 中国
\u534e\u5357 华南
------------------------------------

$s = "\u4e2d\u56fd";
$s=str_replace("\\","%",$s);

function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.{4};|&#\d+;|.+/U",$str,$r);
$ar = $r[0];
#print_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) == "")
$ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "&#") {
echo substr($v,2,-1)."";
$ar[$k] = iconv("UCS-2","GB2312",pack("n",substr($v,2,-1)));
}
}
return join("",$ar);
}

echo unescape($s);
?>

回答2:

utf8 编码 用json_decode 解码就好

json_decode($str)

回答3:

放到 dw里就看出来啦