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