Home >Backend Development >PHP Tutorial >Check if a string is UTF8 encoded

Check if a string is UTF8 encoded

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:02:02909browse
Check if a string is UTF8 encoded转载地址: http://blog.qita.in/?post=418
  1. function is_utf8($string){
  2. return preg_match('%^(?:
  3. [x09x0Ax0Dx20-x7E] # ASCII
  4. | [xC2-xDF][x80-xBF] # non-overlong 2-byte
  5. | xE0[xA0-xBF][x80-xBF] # excluding overlongs
  6. | [xE1-xECxEExEF][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. }
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn