PHP Tutorial Regular Chinese multiple verification methods
gb2312 Chinese character alphanumeric underline regular expression
Preg_match ("/^[". Chr (0XA1). " -". Chr (0xff)." a-za-z0-9_]+$/", $STR);
Look at one more example of judgment
$STR = "China";
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";
}
Coding table
Two-byte character encoding range
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)
PHP Regular Expressions Match Chinese
preg_match ('/^[xa1-xff0-9a-za-z]+$/', $val)
More detailed code
$val =$_get[name];
if (Preg_match ("/^[". Chr (0XA1). " -". Chr (0xFF)."] +$/", $val))
{
An expression to execute
}
Else
{
An expression to execute
}
In PHP to determine whether the string is Chinese
if (Preg_match ("/^[u4e00-u9fa5]+$/", $str)) {
Print ("The string is all Chinese");
} else {
Print ("This string is not all Chinese");
}