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 '
';
var_dump($match1);
var_dump($match2);
image.png

你可能感兴趣的:(preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 8)