The basis of the PHP judgment in English is the asii value of the character, and the asii value of the character is different because of the encoding. In order to write a PHP program to judge Chinese and English characters, we must first understand the Asii value range of the English characters under each encoding:
1. GBK (gb2312/gb18030)
X00-xff GBK Two-byte coding 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)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
</HEAD>
<BODY>
?
$str = "Chinese";
Echo $str;
echo "
if (Preg_match ("/^[". Chr (0XA1). " -". Chr (0xFF)."] +$/", $str)) {//can only be used in GB2312 cases
if (Preg_match ("/^[x7f-xff]+$/", $str)) {//compatible gb2312,utf-8
echo "Correct input";
} else {
echo "Error input";
}
?>
</BODY>
</HTML>