php uncode 轉漢字編碼

(二少)在南極發表於2014-12-23

$test = "%u4E0A%u6D77%u9EC4%u6D66";
//$test = '\u5e86\u91cd\u5e86'; //慶重慶
$temp = explode('%u',$test);// 拆分成陣列
$rslt = array(); // 儲存結果的陣列
array_shift($temp); //去掉第一個不含資料的
foreach($temp as $k => $v) {
$v = hexdec($v); //將16進位制轉換成十進位制
$rslt[] = '&#' . $v . ';'; //轉換成html實體
}
$rslt = implode('',$rslt); //組合結果陣列成字串

echo $rslt;

相關文章