Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 226
Tim Avatar asked Sep 03 '15 12:09

Tim


1 Answers

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]);
like image 85
Roboroads Avatar answered Oct 18 '22 03:10

Roboroads