Find multiple patterns with a single preg_match_all in PHP
Posted
by
Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-12-27T00:28:14Z
Indexed on
2010/12/27
0:54 UTC
Read the original article
Hit count: 138
Using PHP and preg_match_all I'm trying to get all the HTML content between the following tags (and the tags also):
<p>paragraph text</p>
don't take this
<ul><li>item 1</li><li>item 2</li></ul>
don't take this
<table><tr><td>table content</td></tr></table>
I can get one of them just fine:
preg_match_all("(<p>(.*)</p>)siU", $content, $matches, PREG_SET_ORDER);
Is there a way to get all the
<p></p> <ul></ul> <table></table>
content with a single preg_match_all? I need them to come out in the order they were found so I can echo the content and it will make sense.
So if I did a preg_match_all on the above content then iterated through the $matches array it would echo:
<p>paragraph text</p>
<ul><li>item 1</li><li>item 2</li></ul>
<table><tr><td>table content</td></tr></table>
© Stack Overflow or respective owner