Unknown modifier 'l' error [duplicate]
Asked Answered
E

2

0
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'l' in /var/www/test.php on line 9

It's saying my regex has an unknown modifier, but I'm not sure what exactly is happening to trigger the error

preg_match_all("/\<select id\=\'subscription_division_id\'(.+?)</select>\/is", $html, $matches);
Eberly answered 27/1, 2011 at 19:17 Comment(1)
simplehtmldom.sourceforge.netAggappe
M
5

You are escaping wrong. For the regex parser, the following is your regex:

\<select id\=\'subscription_division_id\'(.+?)<

whereas select>\/is is supposed to be the regexp modifiers (the regex string is enclosed in /). Given that the l in there is the first invalid modifier, you receive that error. So to fix that, you need to escape the slash in the closing tag. And btw. you are escaping quite a lot unnecessary things, this is enough:

preg_match_all("/<select id='subscription_division_id'(.+?)<\/select>/is", $html, $matches);
Merchantable answered 27/1, 2011 at 19:21 Comment(1)
+1 Using a different delimiter (typically ~) would be even better, so no escaping is required at all.Urias
U
3

PHP’s PCRE functions require the pattern to be delimited by delimiters that separate the pattern from optional modifiers. But these delimiters need to be escaped if they occur inside the pattern. So you need to escape the delimiters / inside your pattern:

"/\<select id\=\'subscription_division_id\'(.+?)<\/select>/is"
                                                  ^

Otherwise the pattern is ended prematurely and the rest is interpreted as modifiers. Like in your case where the rest (i.e. select>/is) is interpreted as such. s and e are valid modifiers but l isn’t. That’s the reason for your error message.

Uranium answered 27/1, 2011 at 19:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.