php实现utf-8转unicode函数分享
php实现utf-8转unicode函数如何操作呢?需要的朋友可以参考下,代码很简单,功能却很实用,推荐给大家。希望对大家有所帮助!
奉上代码先:
复制代码 代码如下:
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[] = '%'ex($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);
}
-
PHP正则匹配中文字母数字正则的表达式
PHP语言是一门实用性很强的语言,下面小编为大家带来了关于PHP正则匹配中文字母数字正则的'表达式,欢迎大家阅读!PHP正则匹配中文字母数字正则的表达式代码如下if(preg_match("/^d*$/","4312")){echo"全数字";}if(preg_match("/^[a-z]*$/i","fdsFDfd")){echo"全...
-
php环境怎么配置
使用php集成环境可以轻松实现php一键安装,搭建php开发环境;phpnow,xampp,phpstudy是Windows平台上最常用的三个php集成开发环境。以下是小编为大家搜索整理的PHP环境配置的方法,欢迎大家阅读!更多精彩内容请及时关注我们考试网!运行环境配置:php54+Apache2.2+Mysq...
-
PHP编程常用技巧四则
PHP具有非常强大的功能,所有的CGI的功能PHP都能实现。下面就来和小编一起看看PHP编程常用技巧四则吧。1.配置PHP文件目录作为服务器端解释执行的脚本语言,PHP程序放置在某个服务器可以访问的目录下,一般可以通过修改Apache的进行配置,例如我们在该文件中的一句:Ali...
-
tp搜索时首页分页和搜索页保持条件分页的方法
在做搜索查询时突然发现在首页用的`分页代码在搜索页使用时出现错误,首页分页代码(代码中标注start与end部分为分页代码),下面是由本站小编为大家整理的Thinkphp搜索时首页分页和搜索页保持条件分页的方法,喜欢的可以收藏一下!了解更多详情资讯,请关注应届毕业生...
相关文章
- 谈谈php中的unicode和utf8编码
- 八年级《unit8 Why don’t you get her a scarf? Period1》评课稿
- php的file-put-contents()功能函数
- Efforts Urged to Improve Womens Reproductive Health英语阅读
- PEP六年级上册《Unit1Howdoyougotoschool》知识点归纳
- Identifyingpeoplebyoccupation辨别身份实用英语口语
- Zend studio for eclipse中使php可以调用mysql相关函数的设置方
- PHP如何实现Unicode和Utf-8编码相互转换
- 九年级《unit 6 I like music that I can dance to. Period2》评课稿
- php中ftp-chdir() ftp-cdup()函数用法