如果用正则筛选中文的时候,需要在规则后面添加字符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);

得到的筛选结果为:
preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 8

相关文章:

  • 2021-05-02
  • 2021-12-30
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2022-01-19
  • 2021-08-18
  • 2021-10-14
  • 2022-12-23
相关资源
相似解决方案