title: How to explode string by selected html tags
body: <p>I need to explode string, which contains (not valid) HTML, by selected tags - <code>&lt;p&gt;, &lt;ol&gt;, &lt;ul&gt;, &lt;table&gt;, &lt;h1-6&gt;</code> . If any tags are nested, string should be exploded only by first one.</p>
  
  <p>Inserted input:</p>
  
  <pre><code>  &lt;div id="main"&gt;
    &lt;h1 id="heading"&gt;Heading h1&lt;/h1&gt;
    &lt;p&gt;
    &lt;ol&gt;
      &lt;li&gt;abc&lt;/li&gt;
      &lt;li&gt;def&lt;/li&gt;
      &lt;li&gt;ghi&lt;/li&gt;
    &lt;/ol&gt;
    Lorem ipusm lorem ipsum Lorem ipusm lorem ipsum Lorem ipusm lorem ipsum Lorem ipusm.
    &lt;/p&gt;
    &lt;p&gt;Test test test test test&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;aaa&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>Exptected output:</p>
  
  <pre><code>$output[0] = '&lt;div id="wrapp"&gt;&lt;h1 id="heading"&gt;Heading h1&lt;/h1&gt;';
  $output[1] = '&lt;p&gt;&lt;ol&gt;&lt;li&gt;abc&lt;/li&gt;&lt;li&gt;def&lt;/li&gt;&lt;li&gt;ghi&lt;/li&gt;&lt;/ol&gt;Lorem ipusm lorem ipsum Lorem ipusm lorem ipsum Lorem ipusm lorem ipsum Lorem ipusm.&lt;/p&gt;';
  $output[2] = '&lt;p&gt;Test test test test test&lt;/p&gt;';
  $output[3] = '&lt;ul&gt;&lt;li&gt;aaa&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;';
  </code></pre>
  
  <p>I have tried a few DOM libraries, but no one can not what I need. The biggest problem is split div#main element and nested tags (not valid html). I appreciate any ideas.</p>