title: How to delete empty tags using PHP "new DomDocument ()"?
body: <p>I'm using PHP &quot;new DomDocument ()&quot;. I want to delete tags whose content is empty from the specified effects. But the code below doesn't work. How can I do that?</p>
  <pre><code>$html = '&lt;blockquote&gt;
  &lt;p&gt;Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s,&lt;/p&gt;
  &lt;/blockquote&gt;
  &lt;p&gt;8&lt;/p&gt;
  &lt;hr&gt;
  &lt;p&gt;&lt;/p&gt;
  &lt;strong&gt;&lt;/strong&gt;
  &lt;a href=&quot;&quot; title=&quot;Link Name&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;
  &lt;img src=&quot;tex.png&quot; /&gt;
  &lt;span&gt;&lt;/span&gt;
  &lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;
  &lt;ol&gt;&lt;li&gt;&lt;/li&gt;&lt;/ol&gt;
  &lt;em&gt;&lt;/em&gt;
  &lt;u&gt;&lt;/u&gt;
  &lt;s&gt;&lt;/s&gt;
  &lt;blockquote&gt;&lt;/blockquote&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;';
  
  
  $dom = new DomDocument();
  $dom-&gt;loadHTML($html);
  $xpath = new DOMXPath($dom);
  
  // Selects tags to be processed.
  $tags_list = $xpath-&gt;query(&quot;//p|//br|//a|//strong|//img|//ul|//ol|//li|//em|//u|//s|//hr|//blockquote&quot;);
  
  foreach($tags_list as $tag) {
  
     // Checks and deletes tags with empty content.
     if(  in_array($tag-&gt;tagName, ['p','a','strong','blockquote']) ){
          if( $tag-&gt;nodeValue == &quot;&quot; ){
              $tag-&gt;parentNode-&gt;removeChild($tag);
          }
      }   
          
  }
  
  $cleanHtml = $dom-&gt;saveHTML();
  echo $cleanHtml;
  </code></pre>
  <p><strong>Desired Result:</strong></p>
  <pre><code>&lt;blockquote&gt;
  &lt;p&gt;Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s,&lt;/p&gt;
  &lt;/blockquote&gt;
  &lt;p&gt;8&lt;/p&gt;
  &lt;hr /&gt;
  </code></pre>
  <p><strong>I made edits to my code. It is running smoothly now. But I'm trying to remove the <code>&lt;html&gt;&lt;body&gt;</code> tags.</strong></p>
  <p><a href="http://sandbox.onlinephpfunctions.com/code/4551454c5f8d7b239844aef3b5757e24c29fb351" rel="nofollow noreferrer">http://sandbox.onlinephpfunctions.com/code/4551454c5f8d7b239844aef3b5757e24c29fb351</a></p>