把十六進制中文轉爲中文的函數

把16進制中文轉爲中文的函數

$str1 = '{"title":"\u8fd9\u91cc\u662f\u4e2d\u6587\u6807\u9898","body":"abcd..."}';
echo u2utf8($str1);
{"title":"這裏是中文標題","body":"abcd..."}
function u2gbk($str){
    return preg_replace("/\\\u([\da-f]{4})/ie", 'iconv("UCS-2BE","gb2312",pack("H4","\\1"))', $str);
}
function u2utf8($str){
    return preg_replace("/\\\u([\da-f]{4})/ie", 'iconv("UCS-2BE","utf-8",pack("H4","\\1"))', $str);
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章