How to split string into arrays based on html tag : <p>I have a string having HTML tags and I would like to explode into arrays as like below</p>

<p>The tags I am considering to explode are : <code>p, h1, h2, h3, h4, h5, &lt;ul&gt;, &lt;ol&gt;</code></p>

<p>Example: </p>

<pre><code>$data ="&lt;p&gt; Paragraph 1 &lt;/p&gt; &lt;h2&gt;h2 tag 1 &lt;/h2&gt; &lt;p&gt; Paragraph 2.&lt;/p&gt; &lt;p&gt;Paragraph 3 &lt;/p&gt; &lt;ol&gt; &lt;li&gt;pizza&lt;/li&gt; &lt;li&gt;burgers&lt;/li&gt; &lt;li&gt;salad&lt;/li&gt; &lt;/ol&gt; &lt;ul&gt; &lt;li&gt; &lt;ul&gt; &lt;li&gt; One &lt;/li&gt; &lt;li&gt;Twp &lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;p&gt; Paragraph 
 5 &lt;/p&gt; &lt;p&gt;Paragraph 6:&lt;/p&gt; &lt;h4&gt; h4 tag&lt;/h4&gt; &lt;h1&gt; h4 tag&lt;/h1&gt; &lt;h4&gt; h4 tag&lt;/h4&gt;"
</code></pre>

<p>I need the following output:</p>

<pre><code>$array_tags= [
 0 =&gt; &lt;p&gt; Paragraph 1 &lt;/p&gt;,
 1 =&gt; &lt;h2&gt;h2 tag 1 &lt;/h2&gt;,
 2 =&gt; &lt;p&gt; Paragraph 2 &lt;/p&gt;,
 3 =&gt; &lt;p&gt; Paragraph 3 &lt;/p&gt;,
 4 =&gt; &lt;ol&gt; &lt;li&gt;pizza&lt;/li&gt; &lt;li&gt;burgers&lt;/li&gt; &lt;li&gt;salad&lt;/li&gt; &lt;/ol&gt;,
 5 =&gt; &lt;p&gt; Paragraph 4 &lt;/p&gt;,
 6 =&gt; &lt;ul&gt; &lt;li&gt; &lt;ul&gt; &lt;li&gt; One &lt;/li&gt; &lt;li&gt;Twp &lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt;,
 7 =&gt;  &lt;p&gt; Paragraph 5 &lt;/p&gt;,
 8 =&gt;  &lt;p&gt; Paragraph 6 &lt;/p&gt;,
 9 =&gt;  &lt;h4&gt; h4 tag&lt;/h4&gt;,
 10 =&gt; &lt;h1&gt; h1 tag&lt;/h1&gt;,
];
</code></pre>

<p>Could someone please help here? Thanks in advance!</p>
