PHP版 汉字转码的实现详解

前端之家收集整理的这篇文章主要介绍了PHP版 汉字转码的实现详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如下所示:
<div class="codetitle"><a style="CURSOR: pointer" data="2259" class="copybut" id="copybut2259" onclick="doCopy('code2259')"> 代码如下:

<div class="codebody" id="code2259">
<?PHP
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.'
';
?>

原文链接:https://www.f2er.com/php/26335.html

猜你在找的PHP相关文章