PHP Judging Chinese language, English, digital

Source: Internet
Author: User
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 ');


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.