人民网
NCR转字符串的方法:
echo mb_convert_encoding ("人民网", "GBK", "HTML-ENTITIES");
纯函数转换的方法:
<?php
$str = '人民网';
echo convert_unicode($str);
function u2utf8($c) {
$str='';
if ($c < 0x80) {
$str.=$c;
} else if ($c < 0x800) {
$str.=chr(0xC0 | $c>>6);
$str.=chr(0x80 | $c & 0x3F);
} else if ($c < 0x10000) {
$str.=chr(0xE0 | $c>>12);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
} else if ($c < 0x200000) {
$str.=chr(0xF0 | $c>>18);
$str.=chr(0x80 | $c>>12 & 0x3F);
$str.=chr(0x80 | $c>>6 & 0x3F);
$str.=chr(0x80 | $c & 0x3F);
}
return $str;
}
function convert_unicode($source)
{
preg_match_all("/&#([0-9]+)/",$source, $regs);
foreach($regs[1] as $v)
{
$source = str_replace("&#".$v.";",u2utf8($v),$source);
}
return $source;
}