Home > Article > Backend Development > PHP regular matching gb2312 and utf-8 Chinese_PHP tutorial
$action = trim($_get['action']);
if($action == "sub")
{
$str = $_post['dir'];
//if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."a-za-z0-9_]+$/",$str)) //gb2312 Chinese characters Number underline regular expression
if(!preg_match("/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u",$str)) //utf-8 Chinese character alphanumeric underline regular expression
{
echo "The [".$str."] you entered contains illegal characters";
}
else
{
echo "The [".$str."] you entered is completely legal and passed!";
}
}
?>