PHP judgment string is pure English, pure Chinese or Chinese-English mixed _php tutorial

Source: Internet
Author: User
Here are some of my collection of PHP judgment string is pure English, pure Chinese or Chinese-English mixed examples, we can refer to.

Pure English

The code is as follows Copy Code

if (Preg_match ("/^[a-z]*$/i", "FDSFDFD"))

{

echo "Full letter

";

}

Pure Chinese characters

The code is as follows Copy Code

Like what:
var str = "PHP programming";
if (/^[u4e00-u9fa5]+$/.test (str)) {
Alert ("The string is all Chinese");
}
else{
Alert ("The string is not all Chinese");
In PHP, the hexadecimal data is represented by X. Then, change to the following code:
$STR = "PHP programming";
if (Preg_match ("/^[x4e00-x9fa5]+$/", $str)) {
Print ("The string is all Chinese");
} else {
Print ("The string is not all Chinese");
}


Chinese-English mixed

User name: including English lowercase, Chinese characters, numbers, underscores, not all numbers, underline cannot be at the end

The code is as follows Copy Code

/^[a-z0-9_u4e00-u9fa5]+[^_]$/g Utf-8

Preg_match ("/^[a-z0-9_x80-xff]+[^_]$/g", $a); GBK:

Preg_match ("/^[a-z0-9_". Chr (0XA1). " -". Chr (0xff)." +[^_]$/", $a)


UTF-8 encoding

The code is as follows Copy Code


/**
* PHP judgment String Pure Chinese or plain English or Chinese-English mixed
* Jones Taiwan Blog
*/
Echo ' ;
function Utf8_str ($STR) {
$MB = Mb_strlen ($str, ' utf-8 ');
$st = strlen ($STR);
if ($st = = $MB)
Return ' plain English ';
if ($st% $mb ==0 && $st%3==0)
Return ' pure Chinese characters ';
Return ' Chinese-English mix ';
}

$STR = ' Joan Taiwan blog ';
Echo ' string:'. $str. ', yes '. UTF8_STR ($STR). ";
?>

GBK encoding

The code is as follows Copy Code

function Gbk_str ($STR) {
$MB = Mb_strlen ($str, ' GBK ');
$st = strlen ($STR);
if ($st = = $MB)
Return ' plain English ';
if ($st% $mb ==0 && $st%2==0)
Return ' pure Chinese characters ';
Return ' Chinese-English mix ';
}

Digital Chinese characters

The code is as follows Copy Code

$username =$_request[' username '];
if (!preg_match ("/^[a-z0-9xa1-xff]{3,10}$/", $username))
{
echo "34r345";
Exit
}

http://www.bkjia.com/PHPjc/631266.html www.bkjia.com true http://www.bkjia.com/PHPjc/631266.html techarticle here are some of my collection of PHP judgment string is pure English, pure Chinese or Chinese-English mixed examples, we can refer to. The plain English code follows the copy code if (Preg_match (/^[a-z]*$/i, FDSFD ...

  • 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.