title: Append HTML elements by PHP
body: <p>I want to append my <code>head</code> tag with <code>script</code> tag(with some contents) in external <code>Html</code> file using <code>PHP</code> code.
  But my <code>Html</code> is not updating or showing any errors.</p>
  
  <h2>PHP Code:</h2>
  
  <pre><code>&lt;?php
  
  $doc = new DOMDocument();
  $doc-&gt;loadHtmlFile( 'myfolder/myIndex.html');
  $headNode = $doc-&gt;getElementsByTagName('head')-&gt;item(0);
  
  $scriptNode = $doc-&gt;createElement("script");
  $headNode-&gt;appendChild($scriptNode);
  
  echo $doc-&gt;saveXML();
  
  ?&gt;
  </code></pre>
  
  <h2>Html File :</h2>
  
  <p>(A simple html pattern)</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body&gt;&lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I have refered to the documentation <a href="https://www.php.net/manual/en/domnode.appendchild.php" rel="nofollow noreferrer">here</a> 
  Couldn't figure out the problem still.</p>