PHP版汉字转码的实现详解_php技巧
时间:2021-07-01 10:21:17
帮助过:5人阅读
如下所示:
代码如下:
function unicode_encode($str, $encoding='GBK', $prefix='', $postfix=';'){
$str = iconv($encoding, 'UCS-2', $str);
$arrstr = str_split($str, 2);
$unistr = '';
for($i=0, $len=count($arrstr); $i<$len; $i++)
{
$dec = hexdec(bin2hex($arrstr[$i]));
$unistr .= $prefix.$dec.$postfix;
}
return $unistr;
}
$str = '哈哈';
$unistr = unicode_encode($str);
echo $unistr.'
';
?>