Home > Backend Development > PHP Tutorial > String array to detect whether the string is UTF8 encoded code under PHP

String array to detect whether the string is UTF8 encoded code under PHP

WBOY
Release: 2016-07-29 08:38:22
Original
1149 people have browsed it

function is_utf8($string) {
return preg_match('%^(?:
[x09x0Ax0Dx20-x7E] -xBF]                                                                                                                         xBF][x80-xBF] # excluding overlongs
                                                                               # excluding surrogates
                                                              x90-xBF][x80-xBF]{2}                                                                        80-xBF] {2} # plane 16
)*$%xs', $string);
}
The accuracy is basically the same as mb_detect_encoding, both correct and wrong.
Encoding detection cannot be 100% accurate, this thing can basically meet the requirements.​
The above introduces the string array code to detect whether a string is utf8 encoded under PHP, including the content of string array. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template