preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 8

如果用正则筛选中文的时候,需要在规则后面添加字符u,表示使用utf8编码去解析

$reg = '/[\x{4e00}-\x{9fa5}]/u';

例如:

$reg = '/[\x{4e00}-\x{9fa5}]/u';

$str = '我爱你中国';
preg_match($reg, $str, $match1);
preg_match_all($reg, $str, $match2);

echo '<pre>';
var_dump($match1);
var_dump($match2);

得到的筛选结果为:

posted @ 2018-10-23 10:29  itbsl  阅读(639)  评论(0)    收藏  举报