Here's the answer I got from CC Zona on alt.php. Very helpful. I guess I need to read the manual more thouroughly 🙂
<start post>
Here's what I have:
$pattern = "<item><id>1</id>(.*?)</item>";
(This would be to match the first <item> set)
I keep getting errors such as:
Warning: Unknown modifier '<' in...
PCREs are delimited by matching tokens, most commonly forward slashes.
Think of it like having opening and closing tags in HTML: the PCRE parser
looks for everying between the opening token and the first occurance of the
closing token. Anything after the closing toke is then handled as a
modifier. In this case, PRCE sees:
"<" //opening delimiter
"item" //regex
">" //closing delimiter
"<id>1</id>(.*?)</item>" //modifiers; the first one isn't a valid modifier,
so it throws an error
Since you have a forward slash in the regex expression, choose some other
delimiter. Try to select some punctuation chracter that is neither a regex
special character nor is otherwise likely to appear in that regex as it
gets edited in the future. This usually ends up being the tilde "~"
character for me, but use whatever works for you.
Examples:
$pattern = "~<item><id>1</id>(.*?)</item>~iU" //modifiers for case
insensitive and ungreedy
$pattern = "|<item> <id> 1 </id> (.*?) </item>|x" //modifier making
whitespace insignificant, nice when you have long regexs
$pattern = "{<item> <id> 1 </id> (.*?) </item>}e" //modifier allowing
replacement to include evaluatable PHP code
Note that some valid "matching" delimiters don't have to be the same
character, like in the last case, where opening and closing curly braces
are used as delimiters.