我用mb_detect_encoding函数读出来这个是ASCII编码,//& # x4eca;& #x4f55;& #x5728;& #x4f5c;& #x54c1;(我把&#中间加了空格,不然浏览器自动转码了)但是我不知道怎么转成中文,有人能帮帮我么
/**
试试吧
http://stackoverflow.com/questions/18652280/decode-unicode-chars-in-php-by-the-unicode-number
/**
* $str Unicode编码后的字符串
* $decoding 原始字符串的编码,默认GBK
* $prefix 编码字符串的前缀,默认"&#"
* $postfix 编码字符串的后缀,默认";"
*/
function unicode_decode($unistr, $encoding = 'GBK', $prefix = '&#', $postfix = ';') {
$arruni = explode($prefix, $unistr);
$unistr = '';
for($i = 1, $len = count($arruni); $i < $len; $i++) {
if (strlen($postfix) > 0) {
$arruni[$i] = substr($arruni[$i], 0, strlen($arruni[$i]) - strlen($postfix));
}
$temp = intval($arruni[$i]);
$unistr .= ($temp < 256) ? chr(0) . chr($temp) : chr($temp / 256) . chr($temp % 256);
}
return iconv('UCS-2', $encoding, $unistr);
}
$unistr='&# 4eca;& #x4f55;& #x5728;& #x4f5c;& #x 54c1;' ; echo unicode_decode($unistr);