绿色天空

有大量电子书和大家分享.... 

http://greenskys.gbaopan.com/



自动判断字符是否是UTF-8 编码
greenskys 发表于 2008-7-24 10:20:00

<?php
// Returns true if $string is valid UTF-8 and false otherwise.
is_utf8($string) {

// From [url=http://w3.org/International/questions/qa-forms-utf-8.html]http://w3.org/International/questions/qa-forms-utf-8.html[/url]
return preg_match('%^(?:
[x09x0Ax0Dx20-x7E] # ASCII
| [xC2-xDF][x80-xBF] # non-overlong 2-byte
| xE0[xA0-xBF][x80-xBF] # excluding overlongs
| [xE1-xECxEExEF][x80-xBF]{2} # straight 3-byte
| xED[x80-x9F][x80-xBF] # excluding surrogates
| xF0[x90-xBF][x80-xBF]{2} # planes 1-3
| [xF1-xF3][x80-xBF]{3} # planes 4-15
| xF4[x80-x8F][x80-xBF]{2} # plane 16
)*$%xs', $string);

}
?>


阅读全文 | 回复(0) | 引用通告 | 编辑


发表评论:

    大名:
    密码: (游客无须输入密码)
    主页:
    标题:
    正在载入数据,请稍候……


 
  日历  •  Calendar

<<  < 2008 - >  >>
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

  登录  •  Login


  我的分类  •  Label


  最新日志  •  Lastest


  最新评论  •  Comment
 

  Blog统计  •  Statistic
 

  • 日志:123
  • 评论:63
  • 留言:3
  • 访问:

  友情链接  •  Links

Powered By ShineBlog.com

  给我留言  •  Message


  搜索  •  Search