I've a string with a markup like this:
<h3></h3>
<p><span><strong></strong></span></p>
<p></p>
<div></div>
<p></p>
<p></p>
<img />
<div></div>
And I want to group all tags into sections. But except divs and imgs. These both tags should be in their own section and should not be grouped together. So the result should be like this:
<section>
<h3></h3>
<p><span><strong></strong></span></p>
<p></p>
</section>
<section>
<div></div>
</section>
<section>
<p></p>
<p></p>
</section>
<section>
<img />
</section>
<section>
<div></div>
</section>
How can I do this with php?