PHP UTF-8和Unicode编号互转(多语言)
来源:互联网 发布:java邮箱验证码的实现 编辑:程序博客网 时间:2024/06/07 08:27
- /**
- * utf-8 转unicode
- *
- * @param string $name
- * @return string
- */
- function utf8_unicode($name){
- $name = iconv('UTF-8', 'UCS-2', $name);
- $len = strlen($name);
- $str = '';
- for ($i = 0; $i < $len - 1; $i = $i + 2){
- $c = $name[$i];
- $c2 = $name[$i + 1];
- if (ord($c) > 0){ //两个字节的文字
- $str .= '\u'.base_convert(ord($c), 10, 16).str_pad(base_convert(ord($c2), 10, 16), 2, 0, STR_PAD_LEFT);
- //$str .= base_convert(ord($c), 10, 16).str_pad(base_convert(ord($c2), 10, 16), 2, 0, STR_PAD_LEFT);
- } else {
- $str .= '\u'.str_pad(base_convert(ord($c2), 10, 16), 4, 0, STR_PAD_LEFT);
- //$str .= str_pad(base_convert(ord($c2), 10, 16), 4, 0, STR_PAD_LEFT);
- }
- }
- $str = strtoupper($str);//转换为大写
- return $str;
- }
- /**
- * unicode 转 utf-8
- *
- * @param string $name
- * @return string
- */
- function unicode_decode($name)
- {
- $name = strtolower($name);
- // 转换编码,将Unicode编码转换成可以浏览的utf-8编码
- $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
- preg_match_all($pattern, $name, $matches);
- if (!empty($matches))
- {
- $name = '';
- for ($j = 0; $j < count($matches[0]); $j++)
- {
- $str = $matches[0][$j];
- if (strpos($str, '\\u') === 0)
- {
- $code = base_convert(substr($str, 2, 2), 16, 10);
- $code2 = base_convert(substr($str, 4), 16, 10);
- $c = chr($code).chr($code2);
- $c = iconv('UCS-2', 'UTF-8', $c);
- $name .= $c;
- }
- else
- {
- $name .= $str;
- }
- }
- }
- return $name;
- }
0 0
- PHP UTF-8和Unicode编号互转(多语言)
- PHP UTF-8和Unicode编号互转(多语言)
- PHP UTF-8和Unicode编号互转
- php unicode转utf-8
- php unicode转utf-8编码 解析
- UTF-8转Unicode 编码 C语言
- UTF-8和Unicode
- unicode 和 UTF-8
- Unicode 和 UTF-8
- Unicode和utf-8
- unicode和utf-8
- Unicode和UTF-8
- Unicode 和 UTF-8
- Unicode和UTF-8
- Unicode和UTF-8
- utf-8和unicode
- UTF-8和unicode
- Unicode 和 UTF-8
- SVN服务器搭建
- sql之left join、right join、inner join的区别
- 函数的缺省参数
- 原码, 反码, 补码 详解
- Android_开源框架_AndroidUniversalImageLoader网络图片加载
- PHP UTF-8和Unicode编号互转(多语言)
- linux iptables icmp重定向redirect
- 。。。
- Binary Tree Level Order Traversal
- 你对软件开发中迭代的含义的理解
- Android Fragment应用实战,使用碎片向ActivityGroup说再见
- LINUX下解决MYSQL区分大小写问题
- Android 应用的动画实践--View Animation篇
- 使用ISO镜像制作适用于OpenStack的云镜像