title: Check or validate html tags in php
body: <p>I rally tried a lot. I have googled, but I still cannot figure out how to solve this problem. That is, I'm having the same output 'this document is invalid' for both inputs and a warning. This is my code:</p>
  
  <pre><code>$correct_structure = ['&lt;a&gt;', '&lt;div&gt;', '&lt;/div&gt;', '&lt;/a&gt;', '&lt;span&gt;', '&lt;/span&gt;'];
  
  $incorrect_structure = ['&lt;a&gt;', '&lt;div&gt;', '&lt;/a&gt;', '&lt;p&gt;' , '&lt;/tr&gt;'];
  
  function validate_html_tags($html_tags) {
  
  $tags = htmlspecialchars(implode("", $html_tags));
  $html_doc="&lt;!DOCTYPE html&gt;" . "&lt;html&gt;&lt;body&gt;" . $tags . "&lt;/body&gt;&lt;/html&gt;";    
  $dom = new DOMDocument;
  $dom-&gt;loadHTML($html_doc);
  $dom-&gt;saveHTML();
  
  if ($dom-&gt;validate()) {
      echo "This document is valid!\n";
  } else {
      echo "This document is invalid!\n";
  }
  
  return $tags;   
  </code></pre>
  
  <p>}</p>
  
  <pre><code>The Warnings: 
  Warning: DOMDocument::validate(): No declaration for element html
  Warning: DOMDocument::validate(): No declaration for element body in 
  This document is invalid!
  </code></pre>