PHP版 汉字转码的实现详解_php教程-查字典教程网
PHP版 汉字转码的实现详解
PHP版 汉字转码的实现详解
发布时间:2016-12-29 来源:查字典编辑
摘要:如下所示:复制代码代码如下:

如下所示:

复制代码 代码如下:

<?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 = '<b>哈哈</b>';

$unistr = unicode_encode($str);

echo $unistr.'<br />';

?>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类