title: PHP : inject javascript code inside the html file
body: <p>i want to write/inject a javascript code inside a html file "template.html". </p>
  
  <pre><code>&lt;div id="scr"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>and javascript is</p>
  
  <pre><code>&lt;script&gt;
      window.onload = function(){}
  &lt;/script&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>        $doc = new DOMDocument();
  
          $doc-&gt;loadHTMLFile("template.html");
  
          $doc-&gt;getElementById('scr')-&gt;nodeValue="&lt;script&gt;window.onload = function(){}&lt;/script&gt;"; 
  
          $doc-&gt;saveHTMLFile("html/".$name.".html");
  </code></pre>
  
  <p>What i am getting is</p>
  
  <pre><code>&lt;div id="scr"&gt;&amp;lt;script&amp;gt;window.onload = function(){}&amp;lt;/script&amp;gt;&lt;/div&gt;
  </code></pre>
  
  <p>What i am expecting:</p>
  
  <pre><code>&lt;div id="scr"&gt;&lt;script&gt;window.onload = function(){}&lt;/script&gt;&lt;/div&gt;
  </code></pre>