I’m getting this odd error in the preg_match() function:
Warning: preg_match(): Compilation failed: range out of order in character class at offset 54
The line which is causing this is:
preg_match("/<!--GSM\sPER\sNUMBER\s-\s$gsmNumber\s-\sSTART-->(.*)<!--GSM\sPER\sNUMBER\s-\s$gsmNumber\s-\sEND-->/s", $fileData, $matches);
What this regular expression does is parse an HTML file, extracting only the part between:
<!--GSM PER NUMBER - 5550101 - START-->
and:
<!--GSM PER NUMBER - 5550101 - END-->
Do you have a hint about what could be causing this error?
If
$gsmNumbercontains a square bracket, backslash or various other special characters it might trigger this error. If that’s possible, you might want to validate that to make sure it actually is a number before this point.Edit 2016:
There exists a PHP function that can escape special characters inside regular expressions:
preg_quote().Use it like this:
Obviously in this case because you’ve used the same string twice you could assign the quoted version to a variable first and re-use that.