gvanto;10909377 wrote:Warning: preg_match() [function.preg-match]: Unknown modifier ']'
I tested Nog's take-2 and it worked as well. The warning you are getting is is most likely because you are using a certain character as an opening delimiter, but have the equivalent of a closing delimiter character somewhere in your pattern [other than the actual closing delimiter]. This in turn causes the regex engine to see that equivalent closing delimiter character as indeed the final actual closing delimiter and thus all the remaining characters after that as modifiers, which will quickly land you into trouble...
some example could be something like:
preg_match('[(\d+)[^]]+]', $text, $match);
or
preg_match('%(\d+)[^%+]%', $text, $match);
This gives the + sign an unknown modifier, as the first ] (or % in the second example) character in the pattern causes the regex engine to treat it as the closing delimiter (thus, characters that follow must be legal modifiers (such as i, s, u etc...). The + sign is not a legal modifier, hence the error:
Warning: preg_match() [function.preg-match]: Unknown modifier '+'
The best solution to unknown modifiers is to use characters for delimiters that are not found within your pattern. I would suggest stuff like #, ! or ~, as these are 'generally safer' to use. Otherwise, you will need to escape seeming closing character(s) within your actual pattern.
So the solution to the second example would be:
preg_match('%(\d+)[^\%+]%', $text, $match);