title: How to wrap all fragments (that are not inside of <div> or <h>) with <p>?
body: <p>I have a code:</p>
  
  <pre><code>$html = 
  '&lt;h1&gt;Headline&lt;/h1&gt;
  That should be paragraph 1.
  
  That should be paragraph 2.
  
  &lt;div&gt;Something.&lt;/div&gt;
  That should be paragraph 3.
  ';
  </code></pre>
  
  <p>And I want to change it into:</p>
  
  <pre><code>$html = 
  '&lt;h1&gt;Headline&lt;/h1&gt;
  &lt;p&gt;That should be paragraph 1.&lt;/p&gt;
  
  &lt;p&gt;That should be paragraph 2.&lt;/p&gt;
  
  &lt;div&gt;Something.&lt;/div&gt;
  &lt;p&gt;That should be paragraph 3.&lt;/p&gt;
  ';
  </code></pre>
  
  <p><strong>But how to achieve it in PHP?</strong></p>
  
  <p>I was thinking about replacing each empty line with <code>&lt;p&gt;</code>, <code>&lt;/p&gt;</code>, or <code>&lt;/p&gt;&lt;p&gt;</code>, based on some counter of open/close paragraphs. But that would force user to make such new lines after every <code>&lt;/h1&gt;</code>.</p>
  
  <p>Maybe some <strong>regular expression</strong> would do the job without limiting user to "you have to make new lines after <code>&lt;/h1&gt;</code> and before <code>&lt;h1&gt;</code>"?</p>
  
  <p><strong>The more general the approach is, the better.</strong></p>