String array php checks whether the string is utf8 encoded code

Source: Internet
Author: User
String array: string array php check whether the string is utf8 encoded code: functionis_utf8 ($ string) {returnpreg_match (% ^ (? : [X09x0Ax0Dx20-x7E] # ASCII | [xC2-xDF] [x80-xBF] # non-overlong2-byte function is_utf8 ($ string ){
Return preg_match ('% ^ (? :
[\ X09 \ x0A \ x0D \ x20-\ x7E] # ASCII
| [\ XC2-\ xDF] [\ x80-\ xBF] # non-overlong 2-byte
| \ XE0 [\ xA0-\ xBF] [\ x80-\ xBF] # excluding overlongs
| [\ XE1-\ xEC \ xEE \ xEF] [\ 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 );
}
The accuracy is basically the same as that of mb_detect_encoding. if the accuracy is correct, an error is returned.
Encoding detection cannot be 100% accurate, which can basically meet requirements.

The above introduces the code to check whether the string is utf8 encoded in the string array php, including the content of the string array, and hope to help friends who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.