The basis for PHP to judge Chinese and English is the ASII value of the character, and the ASII value of the character is also different due to different encodings. In order to write a PHP program that determines Chinese and English characters, we must first understand the ASII value range of Chinese and English characters in each encoding:
1. GBK (GB2312/GB18030)
x00-xff GBK double-byte encoding range
x20-x7f ASCII
xa1-xff Chinese gb2312
x80-xff Chinese gbk
2. UTF-8 (Unicode)
u4e00-u9fa5 (Chinese)
x3130-x318F (Korean
xAC00-xD7A3 (Korean)
u0800-u4e00 (Japanese)
//if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) { //Can only be used in the case of GB2312
if (preg_match("/^[x7f-xff]+$/", $str)) { //Compatible with gb2312, utf-8
echo "Enter correctly";
} else {
echo "Wrong input";
}
?>