About the capture of preg_match_all & lt; div & gt; & lt; h1 & gt; title 1 & lt;/h1 & gt; & lt; p & gt; content 1 & lt; /p & gt; & lt; p & gt; content 2 & lt;/p & gt; & lt; h1 & gt; title 2 & lt;/h1 & gt; & lt; p & gt; content 1 & lt;/p & gt; & lt; p & gt capture of preg_match_all
Title 1
Content 1
Content 2
Title 2
Content 1
Content 2
Content 3
Content 4
Title 3
Content 1
Content 2
Content 3
I want to use preg_match_all () to cyclically retrieve the content from the next
Title 1
Content 1
Content 2
------------
Title 2
Content 1
Content 2
Content 3
Content 4
------------
Title 3
Content 1
Content 2
Content 3
I thought about using
preg_match_all('/[\w\W]*<(h1|\/div)/U',$html, $out)
However, this will skip the next step, because the second one has been used by the first one.
------ Solution --------------------
preg_match_all('/(.*)<\/div>/is', $str, $m);
$m = explode('', substr($m[1][0], 5));
foreach($m as $x)
echo htmlspecialchars ("$x") . '
';