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

可紊 提交于 2019-12-10 12:36:10

问题


I am writing up some PHP code. In this code, I am running a for loop within a for loop to iterate over an array, then to iterate over the characters in the current string in the array.

I then want to do preg_match() on the current string to see if it matches a rather ling 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])

But I keep on receiving the following error:

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


回答1:


Add UTF-8 parsing, you are not in UFT8 mode. Add the u parameter.

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]);

Also, i'd like to emphasize too that you have a typo. \x{2000-} should be \x{2000} or \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]);


来源:https://stackoverflow.com/questions/32375531/preg-match-compilation-failed-character-value-in-x-or-o-is-too-large-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!