PHP版 汉字转码的实现详解

yipeiwu_com6年前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实现递归复制整个文件夹的类。分享给大家供大家参考。具体如下: <?php /* * 文件夹复制类 */ class CopyFile { pub...

PHP多文件上传类实例

本文实例讲述了PHP多文件上传类。分享给大家供大家参考。具体如下: 复制代码 代码如下:<?php /* PHP多文件上传类 修改:Linvo 2008-2-15 */...

PHP setcookie() cannot modify header information 的解决方法

使用setcookie()函数时总是报以下错误: Warning: Cannot modify header information - headers already sent by....

THINKPHP支持YAML配置文件的设置方法

为什么要用 yaml 因为 Yaml 简单,而且对人类友好; Yaml: http://www.yaml.org/ 在哪里会用到? 最基本的,在 ThinkPHP 的配置文件里面就可以选...

PHP下常用正则表达式整理

--------------------------------------------------------- 正则收藏 手机号码: $mode = "/^1[358]\d{9}/"...