preg_match():编译失败:\x{} 或 \o{} 中的字符值在第 25 行的偏移量 27 处太大

preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 27 on line number 25

我正在编写一些 PHP 代码。在这段代码中,我是运行一个for循环中的for循环来遍历一个数组,然后遍历数组中当前字符串中的字符。

然后我想对当前字符串执行 preg_match() 以查看它是否与相当长的 RegEx 匹配。

preg_match('/[ \f\n\r\t\v\x{00a0}\x{1680}\x{180e}\x{2000-}\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}\x{feff}]/', $input[$i][$j])

但我不断收到以下错误:

WARNING preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 27 on line number 25

添加UTF-8解析,你不是UFT8模式。添加 u 参数。

preg_match('/[ \f\n\r\t\v\x{00a0}\x{1680}\x{180e}\x{2000-}\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}\x{feff}]/u', $input[$i][$j]);

另外,我也想强调一下,你打错了。 \x{2000-} 应该是 \x{2000}\x{2000}-:

preg_match('/[ \f\n\r\t\v\x{00a0}\x{1680}\x{180e}\x{2000}\x{200a}\x{2028}\x{2029}\x{202f}\x{205f}\x{3000}\x{feff}]/u', $input[$i][$j]);