All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
PHP中用正则表达式验证中文的问题_php资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/27 19:52:26 Browse times: 326 Comment times: 0

PHP中用正则表达式验证中文的问题_php资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

PHP中用正则表达式验证中文的问题_php资料_编程技术-你的首页-uuhomepage.com

$str = '中华人民共和国123456789abcdefg';
echo preg_match("/^[\u4e00-\u9fa5_a-zA-Z0-9]{3,15}$",$strName);

运行一下上面这段代码,看会有什么提示信息?
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

原来,PHP正则表达式中不支持下列 Perl 转义序列:\L, \l, \N, \P, \p, \U, \u, or \X

在 UTF-8 模式下,允许用“\x{...}”,花括号中的内容是表示十六进制数字的字符串。原来的十六进制转义序列 \xhh 如果其值大于 127 的话则匹配了一个双字节 UTF-8 字符。
所以,可以这样来解决preg_match("/^[\x80-\xff_a-zA-Z0-9]{3,15}$",$strName);






There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.