$a = '华诺国际';
echo html2char($a);
file_put_contents('test.txt',_htmltochar($a));
exit;
//将html汉字实体数字编码转换为汉字
//yangyu{at}sina.cn
function html2char($html){
return preg_replace('/(/&/#)(/d{5});/mise',"iconv('UCS-2','GBK',pack('H4',dechex(//2)) )", $html);
}
function _htmltochar($dec){
$dec = str_replace(array('&','#'),'',$dec);
$dec = split('[;;]',rtrim($dec,';'));
$utf = '';
foreach ($dec as $v){
$utf .= chr(224 + (($v - ($v % 4096)) / 4096));
$utf .= chr(128 + ((($v % 4096) - ($v % 64)) / 64));
$utf .= chr(128 + ($v % 64));
}
return $utf;
}
function phpunescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","utf-8",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "&#x")
$ar[$k] = iconv("UCS-2","utf-8",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "&#") {
$ar[$k] = iconv("UCS-2","utf-8",pack("n",substr($v,2,-1)));
}
}
return join("",$ar);
}