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);
}
Accuracy is basically the same as mb_detect_encoding, to be right together, to be wrong together.
Code detection is not possible 100% accurate, this thing has been able to basically meet the requirements.
http://www.bkjia.com/PHPjc/319259.html www.bkjia.com true http://www.bkjia.com/PHPjc/319259.html techarticle Functionis_utf8 ($string) {Returnpreg_match ('%^ (?: [\x09\x0a\x0d\x20-\x7e] #ASCII |[ \XC2-\XDF][\X80-\XBF] #non-overlong2-byte |\XE0[\XA0-\XBF][\X80-\XBF] #excludingoverlongs | [\xe1-\xec ...