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.