I have a string with multiple tags in as so:
<item>foo bar</item> <item>foo bar</item>
I need to match each of these and they can be on new lines and add them to an array, it can't seem to match them though, I'm new to regex so I'm not understanding what is going wrong, an explanation would be great, thanks!
preg_match_all('/<item>(.*)<\/item>/',$content,$matches);
At the moment, it returns two empty index in the matches array.
I have also tried:
<item>([\s\S]*)<\/item>
This matches from the first tag until the very last one, so grabs everything essentially.
preg_match_all('/(<item>(.*?)<\/item>)/',$content,$matches);.*is greedy and wants everything it can grab. Depending on what you mean bynew linesthis also could behave differently. There are modifiers you could use to affect these behaviors. Look at theUandsmodifiers, php.net/manual/en/reference.pcre.pattern.modifiers.php.