title: Get tags values from every tag inside nested tags in html with php
body: <p>I'm working in code that get all tags values "Text only" from html file. But if any tag has nested tags it will go inside Childs and get the the tag value that hasn't a child.
  I tried this one but it has a bit of missing</p>
  
  <p>php code:</p>
  
  <pre><code>$dochtml = new DOMDocument();
  $dochtml-&gt;loadHTMLFile("index2.html");
  $nodes = $dochtml -&gt;getElementsByTagName("a"); 
  gettagsvalue($nodes);
    function gettagsvalue($nodes){
      if($nodes-&gt;length != 0){
        for ($i=0;$i&lt;$nodes-&gt;length;$i++){
          foreach ($tags=["h1","h2","h3","h4","h5","h6","h7","a","img","li","span","p","pre","i","strong","div","ul"] as $tag){  
            if($nodes-&gt;item($i)-&gt;getElementsByTagName($tag)-&gt;length != 0){
              if ($nodes-&gt;item($i)-&gt;getElementsByTagName($tag)-&gt;length == 1){
                echo "here"."&lt;br&gt;&lt;br&gt;&lt;br&gt; $tag";
                echo "&lt;pre&gt;" ;print_r($nodes-&gt;item($i)-&gt;getElementsByTagName($tag)-&gt;item(0));echo "&lt;/pre&gt;" ;             
              }else{
                echo "there"."&lt;br&gt;&lt;br&gt;&lt;br&gt; $tag";
                gettagsvalue($nodes-&gt;item($i)-&gt;getElementsByTagName($tag));
                // echo "$tag &lt;br&gt;&lt;br&gt;&lt;br&gt;";
              }
              // print_r($nodes-&gt;item($i)-&gt;getElementsByTagName($tag));echo "&lt;br&gt;"; 
            }        
        }
      }
    }
  }
  </code></pre>
  
  <p>i expected to get </p>
  
  <p>"Green"
  "valley" </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;a href="index.html" id="aaaaaaaaaaaa2015284957"&gt;
      &lt;img src="images/logo.png" width="50px" height="50px" id="imgaaaaaaaaaaimg732756221"&gt;
      &lt;span&gt;Green&lt;/span&gt;
      &lt;span id="spanaaaaaaaaaaspan1106733773"&gt;Valley&lt;/span&gt;
  &lt;/a&gt;
  </code></pre>