找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 218|回复: 0
打印 上一主题 下一主题

PHP实现Unicode编码相互转换的方法示例

[复制链接]

2500

主题

2513

帖子

7520

积分

论坛元老

Rank: 8Rank: 8

积分
7520
跳转到指定楼层
楼主
发表于 2018-2-14 05:26:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文实例讲述了PHP实现Unicode编码相互转换的方法。分享给大家供大家参考,具体如下:
0) {
   if (ord(substr($str, $cind, 1))  $value) {
  $unicodestr.= $prefix . base_convert(bin2hex(iconv('utf-8', 'UCS-4', $value)), 16, 10) .$postfix;
}
return $unicodestr;
}
/**
* $str Unicode编码后的字符串
* $decoding 原始字符串的编码,默认utf-8
* $prefix 编码字符串的前缀,默认"&"
* $postfix 编码字符串的后缀,默认";"
*/
function unicode_decode($unistr, $encoding = 'utf-8', $prefix = '&', $postfix = ';') {
$arruni = explode($prefix, $unistr);
$unistr = '';
for ($i = 1, $len = count($arruni); $i  0) {
   $arruni[$i] = substr($arruni[$i], 0, strlen($arruni[$i]) - strlen($postfix));
  }
  $temp = intval($arruni[$i]);
  $unistr .= ($temp
PS:这里再为大家提供几款Unicode编码转换操作相关工具供大家参考使用:
在线Unicode/中文转换工具:
http://tools.jb51.net/transcoding/unicode_chinese
Native/Unicode在线编码转换工具:
http://tools.jb51.net/transcoding/native2unicode
在线中文汉字/ASCII码/Unicode编码互相转换工具:
http://tools.jb51.net/transcoding/chinese2unicode
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP编码与转码操作技巧汇总》、《php面向对象程序设计入门教程》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总
希望本文所述对大家PHP程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • 用php实现gb2312和unicode间的编码转换
  • php utf-8转unicode的函数
  • php UTF-8、Unicode和BOM问题
  • PHP中正则表达式对UNICODE字符码的匹配方法
  • 浅析PHP中的UNICODE 编码与解码
  • php制作unicode解码工具(unicode编码转换器)代码分享
  • PHP解码unicode编码的中文字符代码分享
  • php实现utf-8转unicode函数分享
  • PHP解密Unicode及Escape加密字符串
  • 简单谈谈php中的unicode和utf8编码
  • PHP如何实现Unicode和Utf-8编码相互转换
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端