Copy Code code as follows:
$str = ' ASB Tianshui 12 ';
if (Preg_match ("/^[\x7f-\xff]+$/", $str)) {
Echo ' All is Chinese character ';
}else {
Echo ' is not all Chinese characters ';
}
/**
PHP's own judgment 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 entered the combination of Chinese and English numerals! ' <br> ';
echo "Length:". strlen ($STR);
}
/ **
The following two methods are used to determine whether it is a string consisting of English characters and numbers,
Or is it all a string of Chinese characters $str or is it the variable at the beginning of this article
*/
if (Preg_match_all ("/^ ([\x81-\xfe][\x40-\xfe]) +$/", $str, $match)) {
Echo ' All is Chinese character ';
} 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 for two bytes, one Chinese or the number of one, using encoding for UTF-8
*/
<script>
var leng = {};
var value = Document.forms[0].name.value;
Jmz. GetLength = function (str) {
var reallength = 0, Len = str.length, charcode =-1;
for (var i = 0; i < len; i++) {
CharCode = Str.charcodeat (i);
if (charcode >= 0 && charcode <= 128) Reallength + = 1;
else Reallength +=2;
}
return reallength;
};
Alert (Leng. GetLength (value))
</script>
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 ' in Chinese character digital English;}
ElseIf ($a && $b &&! $c) {$output = ' mixed string of kanji numbers ';}
ElseIf ($a &&! $b && $c) {$output = ' mixed string ' in English characters ';}
ElseIf (! $a && $b && $c) {$output = ' mixed string in digital English ';}
ElseIf ($a && $b &&! $c) {$output = ' pure Chinese ';}
ElseIf (! $a && $b &&! $c) {$output = ' pure number ';}
ElseIf (! $a && $b && $c) {$output = ' plain English ';}
return $output;
}
Echo Checkstr (' 5 love u ');