当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP版 汉字转码的实现详解

PHP版 汉字转码的实现详解

2019年04月09日  | 移动技术网IT编程  | 我要评论
如下所示:
复制代码 代码如下:

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网