首页 资料 正文

检查字符串是否是UTF8编码 -php教程-

2024-04-19 20:05:03 23
填写您的邮件地址,订阅我们的精彩内容:转载地址: http://blog.qita.in/?post=418
  1. function is_utf8($string){
  2. return preg_match('%^(?:
  3. [\x09\x0A\x0D\x20-\x7E] # ASCII
  4. | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
  5. | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
  6. | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
  7. | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
  8. | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
  9. | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
  10. | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
  11. )*$%xs', $string);
  12. }
复制代码


-六神源码网 -六神源码网