请问php如何把\u4e2d\u56fd 和\u534e\u5357 转换成中文
发布网友
发布时间:2022-04-26 04:58
我来回答
共3个回答
热心网友
时间:2022-06-20 22:33
这是unicode编码,
\u4e2d\u56fd 中国
\u534e\u5357 华南
------------------------------------
<?php
$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);
?>
热心网友
时间:2022-06-20 22:33
utf8 编码 用json_decode 解码就好
json_decode($str)
热心网友
时间:2022-06-20 22:34
放到 dw里就看出来啦