我是靠谱客的博主 雪白枕头,这篇文章主要介绍PHP版 汉字转码的实现详解,现在分享给大家,希望可以做个参考。

如下所示:

复制代码 代码如下:

<?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版内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(230)

评论列表共有 0 条评论

立即
投稿
返回
顶部