PHP判断一段字符串是不是utf8编码的函数
PHP #utf8 #字符串 #函数2012-05-10 21:02
这个函数也常用,哈。
01 | function yige_isUTF8( $str ){ |
02 | $length = strlen ( $str ); |
03 | for ( $i =0; $i < $length ; $i ++) { |
04 | $high = ord( $str { $i }); |
05 | if (( $high == 0xC0) || ( $high == 0xC1)) { |
06 | return false; |
07 | } elseif ( $high < 0x80) { |
08 | continue ; |
09 | } elseif ( $high < 0xC0) { |
10 | return false; |
11 | } elseif ( $high < 0xE0) { |
12 | if (++ $i >= $length ) return true; |
13 | elseif (( $str { $i }& "\xC0" ) == "\x80" ) continue ; |
14 | } elseif ( $high < 0xF0) { |
15 | if (++ $i >= $length ) { |
16 | return true; |
17 | } elseif (( $str { $i }& "\xC0" ) == "\x80" ) { |
18 | if (++ $i >= $length ) return true; |
19 | elseif (( $str { $i }& "\xC0" )== "\x80" ) continue ; |
20 | } |
21 | } elseif ( $high < 0xF5) { |
22 | if (++ $i >= $length ) { |
23 | return true; |
24 | } elseif (( $str { $i }& "\xC0" ) == "\x80" ) { |
25 | if (++ $i >= $length ) { |
26 | return true; |
27 | } elseif (( $str { $i }& "\xC0" ) == "\x80" ){ |
28 | if (++ $i >= $length ) return true; |
29 | elseif (( $str { $i }& "\xC0" ) == "\x80" ) continue ; |
30 | } |
31 | } |
32 | } |
33 | return false; |
34 | } |
35 | return true; |
36 | } |
相关文章
- PHP获取访问者IP的函数 2012/05/10
- PHP获取目录的md5值的函数 2012/05/10
- PHP淘宝商品num_iid批量生成淘宝客链接的函数 2012/05/09
- PHP函数is_uploaded_file用法 2012/05/09
- PHP传值/传引用/传地址的区别 2012/05/09
- php面试常见问题及答案 2012/05/09
- PHP比较GET/POST 2012/05/09
- PHP的memory_limit限制修改方法 2012/05/08
- php执行事务mysql实例 2012/05/07
- PHP加密解密迅雷/Flashget/QQ旋风等下载地址 2012/05/07