public function utf8_unicode($str) {
$unicode = array();
$values = array();
$lookingFor = 1; for ($i = 0; $i < strlen( $str ); $i++ ) {
$thisValue = ord( $str[ $i ] );
if ( $thisValue < ord('A') ) {
// exclude 0-9
if ($thisValue >= ord('0') && $thisValue <= ord('9')) {
// number
$unicode[] = chr($thisValue);
}
else {
$unicode[] = '%'.dechex($thisValue);
}
} else {
if ( $thisValue < 128) {
$unicode[] = $str[ $i ];
} else {
if ( count( $values ) == 0 ) {
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
}
$values[] = $thisValue;
if ( count( $values ) == $lookingFor ) {
$number = ( $lookingFor == 3 ) ?
( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
$number = dechex($number);
$unicode[] = (strlen($number)==3)?"\u0".$number:"\u".$number;
$values = array();
$lookingFor = 1;
} // if
} // if
}
} // for
return implode("",$unicode);
}

参考文章:http://randomchaos.com/documents/?source=php_and_unicode

php中utf-8转unicode的更多相关文章

  1. 解决“在多字节的目标代码页中,没有此Unicode字符可以映射到的字符”

    今天在处理Google网站管理员中的500错误时发现这样一些URL: http://www.cnblogs.com/Garnai/tag/3D%3F%96%CA/ http://www.cnblogs ...

  2. PHP中对汉字进行UNICODE编码和解码的实现

    <?php /** PHP中对汉字进行UNICODE编码和解码的实现 **/ class Helper_Tool{ //php中的unicode编码转中文 static function uni ...

  3. Python中的str与unicode处理方法

    Python中的str与unicode处理方法 2015/03/25 · 基础知识 · 3 评论· Python 分享到:42 原文出处: liuaiqi627 的博客    python2.x中处理 ...

  4. 在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。 (#1113)

    报错 在使用MySQL-Front导入sql文件时报错1113:在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符. (#1113) 解决方案 导入.sql文件时,单击 选择文件对话 ...

  5. 编码占用的字节数 1 byte 8 bit 1 sh 1 bit 中文字符编码 2. 字符与编码在程序中的实现 变长编码 Unicode UTF-8 转换 在网络上传输 保存到磁盘上 bytes

    小结: 1.UNICODE 字符集编码的标准有很多种,比如:UTF-8, UTF-7, UTF-16, UnicodeLittle, UnicodeBig 等: 2 服务器->网页 utf-8 ...

  6. 聊聊计算机中的编码(Unicode,GBK,ASCII,utf8,utf16,ISO8859-1等)以及乱码问题的解决办法

    作为一个程序员,一个中国的程序员,想来“乱码”问题基本上都遇到过,也为之头疼过.出现乱码问题的根本原因是编码与解码使用了不同而且不兼容的“标准”,在国内一般出现在中文的编解码过程中. 我们平时常见的编 ...

  7. [转]Python中的str与unicode处理方法

    早上被python的编码搞得抓耳挠腮,在搜资料的时候感觉这篇博文很不错,所以收藏在此. python2.x中处理中文,是一件头疼的事情.网上写这方面的文章,测次不齐,而且都会有点错误,所以在这里打算自 ...

  8. (55)Wangdao.com第八天_JavaScript 字符串中使用 \u 输出Unicode字符

    JavaScript中,使用Unicode 需要 \u 进行转义,格式 "\u十六进制" console.log(\u0031); console.log(\u0041); // ...

  9. python中字符编码及unicode和utf-8区别

    ascii和unicode是字符集,utf-8是编码集 字符集:为每一个「字符」分配一个唯一的 ID(学名为码位 / 码点 / Code Point) 编码规则:将「码位」转换为字节序列的规则(编码/ ...

  10. VC++中多字节字符集和Unicode之间的互换

    在Visual C++.NET中,默认的字符集是Unicode,这和Windows默认的字符集是一致的,不过在老的VC6.0等工程中,默认的字符集形式是多字节字符集(MBCS:Multi-Byte C ...

随机推荐

  1. SQL:数据库批量插入数据

    测试中有些功能要求有足够的数据进行测试,当输入字段较多时通过页面添加很慢.业务只关联单个数据库表可以通过数据库批量插入数据 批量插入数据示例: declare @i int--声明变量 --变量初始化 ...

  2. VScode中的golang代码规范太严格,怎么处理。

    在vscode的配置文件settings.json中,加入下面的配置,一般设置为0.8即可. "go.lintFlags": [ "-min_confidence=.8& ...

  3. yum 源搭建

    RHEL系统部署网络yum源 配置网络yum源 RHEL系统本身光盘做成的yum源所提供的软件包有限,在实际使用过程中经常会出现缺包的现象,本文中以CentOS源作为替代,CentOS的软件包和RHE ...

  4. UESTC 1246 拆x3

    用归纳法分析可以知道死循环只有4. 分析一下复杂度,如果n很大并且不是素数,根据基本不等式可以知道 sum factor(n) ≥ 2+n/2 ≍ n/2. 复杂度是O(T*logN*sqrt(N)) ...

  5. POJ-2352 && hdu-1541 Stars---树状数组的运用

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目大意 : 在坐标上有n个星星,如果某个星星坐标为(x, y), 它的左下位置为:(x0,y ...

  6. E. New Reform_贪心,深搜,广搜。

    E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. 【转】Xcode真机测试could not find developer disk image解决方法

    在使用Xcode进行真机调试的时候,有时根据真机的系统不同,会出现could not find developer disk image 错误,这是由于真机系统过高或者过低,Xcode中没有匹配的配置 ...

  8. Compass Card Sales(模拟)

    Compass Card Sales 时间限制: 3 Sec  内存限制: 128 MB提交: 35  解决: 13[提交] [状态] [讨论版] [命题人:admin] 题目描述 Katla has ...

  9. zen-Coding在Notepad++中的使用

    zen-Coding是一款快速编写HTML,CSS(或其他格式化语言)代码的编辑器插件,这个插件可以用缩写方式完成大量重复的编码工作,是web前端从业者的利器. zen-Coding插件支持多种编辑器 ...

  10. Apache.Tomcat 调用Servlet原理之Class类的反射机制,用orc类解释

    有一个兽人类 package com.swift.servlet; public class OrcDemo { private int hp; private int mp; private int ...