PHP实现Unicode编码相互转换的方法示例
php  /  管理员 发布于 7年前   438
本文实例讲述了PHP实现Unicode编码相互转换的方法。分享给大家供大家参考,具体如下: PS:这里再为大家提供几款Unicode编码转换操作相关工具供大家参考使用: 在线Unicode/中文转换工具: Native/Unicode在线编码转换工具: 在线中文汉字/ASCII码/Unicode编码互相转换工具: 更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP编码与转码操作技巧汇总》、《php面向对象程序设计入门教程》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》 希望本文所述对大家PHP程序设计有所帮助。 0) { if (ord(substr($str, $cind, 1)) < 0xA1) { //如果为英文则取1个字节 array_push($arr_cont, substr($str, $cind, 1)); $cind++; } else { array_push($arr_cont, substr($str, $cind, 2)); $cind+=2; } } } foreach ($arr_cont as &$row) { $row = iconv("gb2312", "UTF-8", $row); } //转换Unicode码 foreach ($arr_cont as $key => $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 < $len; $i++) { if (strlen($postfix) > 0) { $arruni[$i] = substr($arruni[$i], 0, strlen($arruni[$i]) - strlen($postfix)); } $temp = intval($arruni[$i]); $unistr .= ($temp < 256) ? chr(0) . chr($temp) : chr($temp / 256) . chr($temp % 256); } return iconv('UCS-2', $encoding, $unistr);}$str = "PHP编程:";$unistr = unicode_encode($str);$unistr2 = unicode_decode($unistr);echo $unistr . '
';echo $unistr2 . '
';$unistr = unicode_encode($str,'GBK','\\u');$unistr2 = unicode_decode($unistr,'GBK','\\u');echo $unistr . '
';echo $unistr2 . '
';
http://tools..net.cn/transcoding/unicode_chinese
http://tools..net.cn/transcoding/native2unicode
http://tools..net.cn/transcoding/chinese2unicode您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号