Home > Article > Backend Development > PHP Chinese and English regular expressions_PHP tutorial
php tutorial Chinese and English regular expressions
"http://www.w3. org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
function funcChinese($str,$num1='',$num2='')//Judge Chinese regularity
{
if($num1!='' and $num2!=''){
return (preg_match("/^([x81-xfe][x40-xfe])
{". $num1.",".$num2."}$/",$str))?true:false;
}else{
return (!eregi("[^x80-xff]","$ str"))?
true:false;
}
}
if( $_POST)
{
if( funcChinese( $_POST['url '] ) )
{
echo 'is Chinese';
}
else
{
exit('is not a valid Chinese');
}
}
//This can only be judged character by character. You can use foreach to process it
?>