Copy codeThe code is as follows:
$str='asbTianshui City 12';
if (preg_match(" /^[x7f-xff]+$/", $str)){
echo 'All are Chinese characters';
}else {
echo 'Not all are Chinese characters';
}
/**
PHP comes with the ability to determine whether it is Chinese,
eregi('[^x00-x7F]', $str ) //Chinese
eregi('[0-9]', $str) // Number
eregi('[a-zA-Z]', $str)//English
*/
if (eregi('[^x00-x7F]', $str) || eregi('[0-9]', $str) || eregi('[a- zA-Z]', $str)){
echo 'What you entered is a combination of Chinese and English numbers!'.'
';
echo "Length:".strlen($str );
}
/ **
The following two methods are used to determine whether it is a string composed of English characters and numbers,
or a string composed entirely of Chinese characters. The variable $str is still the variable at the beginning of this article
*/
if (preg_match_all("/^([x81-xfe][x40-xfe])+$/", $str, $match)) {
echo 'All are Chinese characters';
} else {
echo 'Not all are Chinese characters';
}
if (preg_match("/([x81 -xfe][x40-xfe])/", $str, $match)) {
echo 'Contains Chinese characters';
} else {
echo 'Does not contain Chinese characters';
}
/**
This is a js method. It determines that a Chinese character occupies two bytes, and a Chinese character or number occupies one. The encoding is UTF-8
*/
function checkStr($str) {
$output='';
$a=ereg('['.chr(0xa1).'-'.chr(0xff).']', $str);
$b= ereg('[0-9]', $str);
$c=ereg('[a-zA-Z]', $str);
if($a && $b && $c) { $output='A mixed string of Chinese characters, numbers and English';}
elseif($a && $b && !$c){ $output='A mixed string of Chinese characters and numbers';}
elseif($ a && !$b && $c){ $output='A mixed string of Chinese characters and English';}
elseif(!$a && $b && $c){ $output='A mixed string of numbers and English' ;}
elseif($a && !$b && !$c){ $output='Pure Chinese characters';}
elseif(!$a && $b && !$c){ $output='Pure Number';}
elseif(!$a && !$b && $c){ $output='Pure English';}
return $output;
}
echo checkStr( '5爱u');
http://www.bkjia.com/PHPjc/313518.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/313518.html
TechArticle
Copy the code as follows: $str='asbTianshui City 12'; if (preg_match("/^[x7f -xff]+$/", $str)){ echo 'All are Chinese characters'; }else { echo 'Not all are Chinese characters'; } /** PHP's built-in method of judging whether it is...