title: How to get a list of all html elements in PHP?
body: <p>According to the documentation for <a href="http://php.net/manual/en/domdocument.getelementsbytagname.php" rel="nofollow noreferrer"><code>DOMDocument::getElementsByTagName</code></a>, I can call the function with <code>"*"</code> argument, and get a list of all HTML elements from some HTML code.</p>
  
  <p>However, with the following code:</p>
  
  <pre><code>&lt;?php
    $dom = new DOMDocument();
    $dom-&gt;loadHTML("&lt;html&gt;&lt;body&gt;&lt;div&gt;hello&lt;/div&gt;&lt;div&gt;bye&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;");
    $nodes = $dom-&gt;getElementsByTagName("*");
  
    foreach ($nodes as $node) {
      $new_text= new DOMText($node-&gt;textContent."MODIFIED");
  
      $node-&gt;removeChild($node-&gt;firstChild);
      $node-&gt;appendChild($new_text);
    }
    $content = $dom-&gt;saveHTML();
    echo $content;
  ?&gt;
  </code></pre>
  
  <p>I get a list of only one element, and the result of execution of the code above is:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"&gt;
  &lt;html&gt;hellobyeMODIFIED&lt;/html&gt;
  </code></pre>
  
  <p>while I would expect something like this:</p>
  
  <pre><code>&lt;html&gt;&lt;body&gt;&lt;div&gt;helloMODIFIED&lt;/div&gt;&lt;div&gt;byeMODIFIED&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Shouldn't <code>DOMDocument::getElementsByTagName</code> method return a list of as many HTML elements as available in the HTML code?</p>
  
  <p>Note:  I need  to create DOMText instances explicitly, because I need this to work in PHP 5.4. <code>DOMNode::textContent</code> is accessible for writing only from PHP 5.6</p>