- $ Str = '123456789abcdefg of the People's Republic of China ';
- Echo preg_match ("/^ [\ u4e00-\ u9fa5_a-zA-Z0-9] {} $", $ strName );
- ?>
Run the above code and the prompt will be: Warning: preg_match (): Compilation failed: PCRE does not support \ L, \ l, \ N, \ P, \ p, \ U, \ u, or \ X at offset 3 in F: \ wwwroot \ php \ test. php on line 2 The reason is that the following Perl escape sequences are not supported in PHP regular expressions: \ L, \ l, \ N, \ P, \ p, \ U, \ u, or \ X In UTF-8 mode, '\ x {...}' is allowed, and the content in braces is a string that represents a hexadecimal number. The original hexadecimal escape sequence \ xhh matches a dubyte UTF-8 character if its value is greater than 127. Solution: preg_match ("/^ [\ x80-\ xff_a-zA-Z0-9] {} $", $ strName ); For example:
- /**
- * Php regular expression to verify Chinese characters
- * Edit bbs.it-home.org
- */
- $ Shouji = "hahaha ";
- If (! Preg_match ("/^ [\ x80-\ xff] {6, 30} $/", $ shouji )){
- Echo "nonono ";
- }
- Else {
- Echo "yesyesyes ";
- }
- ?>
|