title: Error removing empty elements from TinyMCE editor using DOMDocument
body: <p>I have two questions:</p>
  
  <ol>
  <li><p>I am using TinyMCE editor and I want to remove empty tags from HTML. I am getting error "DOMDocument::loadHTML(): Unexpected end tag : p" when I pass text from TinyMCE editor and this error disappears when I directly pass text to TinyMCE strange! Please see code below.</p></li>
  <li><p>How do I prevent warning from DomDocument when incorrect HTML is passed?. <code>&lt;strong&gt;Bold Item &lt;/b&gt;&lt;/strong&gt;</code>? </p></li>
  </ol>
  
  <p>Here is an example text</p>
  
  <pre><code>&lt;p style="text-align: justify;"&gt; &lt;/p&gt;
  &lt;p&gt;blah blah blah &lt;strong&gt;&lt;/strong&gt;.&lt;/p&gt;
  &lt;p style="text-align: justify;"&gt; &lt;/p&gt;
  &lt;p&gt;paragraph three!!.&lt;/p&gt;
  </code></pre>
  
  <p>My function</p>
  
  <pre><code>function remove_empty_tags ($text) {
      $dom = new DOMDocument;
      $dom-&gt;loadHTML($text);
  
      // fetch all the wanted nodes
      $xp = new DOMXPath($dom);
      foreach($xp-&gt;query('//*[not(node() or self::br) or normalize-space() = ""]') as $node) {
          $node-&gt;parentNode-&gt;removeChild($node);
      }
  
      // output the cleaned markup
      return $dom-&gt;saveXml($dom-&gt;getElementsByTagName('body')-&gt;item(0) );
   }
  
   echo remove_empty_tags($_POST['mce_editor']);
  </code></pre>