PHP Judging Chinese, English, digital
$str = ' ASB Tianshui 12 ';
if (Preg_match ("/^[\x7f-\xff]+$/", $str)) {
Echo ' All is Kanji ';
}else {
Echo ' is not all Chinese characters ';
}
/**
PHP comes with the judgment 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 ' You typed in Chinese and English numbers and fit Oh! '. '
';
echo "Length:". strlen ($STR);
}
/ **
The following two methods are used to determine whether the English characters and numbers are composed of strings,
Or all of them are Chinese-made strings with variable $str or variables at the beginning of this article
*/
if (Preg_match_all ("/^ ([\x81-\xfe][\x40-\xfe]) +$/", $str, $match)) {
Echo ' All is Kanji ';
} else {
Echo ' is not all Chinese characters ';
}
if (Preg_match ("/([\x81-\xfe][\x40-\xfe])/", $str, $match)) {
Echo ' contains Chinese characters ';
} else {
Echo ' does not contain Chinese characters ';
}
/**
This is the JS method, judged a Chinese character accounted for two bytes, a Chinese or a number of one, using the code 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 = ' mixed string ' of Chinese numerals in English;} ElseIf ($a && $b && $c) {$output = ' mixed string of kanji numbers ';} ElseIf ($a &&! $b && $c) {$output = ' mixed string ' in Chinese characters ';} ElseIf (! $a && $b && $c) {$output = ' mixed string in English ';} ElseIf ($a &&! $b && $c) {$output = ' pure kanji ';} ElseIf (! $a && $b && $c) {$output = ' pure number ';} ElseIf (! $a &&! $b && $c) {$output = ' plain English ';} return $output;} Echo Checkstr (' 5 love u ');