title: How can I append a code to <head> using PHP?
body: <p>I've got a little web project where all pages have a common header file they import before the actual page content. The header file is something like the following:</p>
  
  <pre><code>&lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
      &lt;link rel="stylesheet" type="text/css" href="css/style.css" /&gt;
      &lt;script type="text/javascript" src="js/some_script.js"&gt;&lt;/script&gt;
      &lt;link rel="shortcut icon" href="images/web.ico" /&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>Then all the pages have a <code>&lt;?php include("header.php"); ?&gt;</code>, so they load the <code>&lt;head&gt;</code> tags at the begining.</p>
  
  <p>I'm now coding a new page, that also includes the previous <code>header.php</code>, but it requires a second javascript to load. I can load it without issues using the <code>&lt;script&gt;</code> tag in the middle of the page, but I was wondering if its possible to append it directly to the <code>&lt;head&gt;</code> tag, instead of resting in the middle of the html code.</p>
  
  <p>The actual code looks like something like this:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="css/style.css" /&gt;
          &lt;script type="text/javascript" src="js/some_script.js"&gt;&lt;/script&gt;
          &lt;link rel="shortcut icon" href="images/web.ico" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;Some text here&lt;/p&gt;
          &lt;script type="text/javascript" src="js/another_script.js"&gt;&lt;/script&gt;
          &lt;p&gt;Some more text&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I would like to know how to achieve the following:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="css/style.css" /&gt;
          &lt;script type="text/javascript" src="js/some_script.js"&gt;&lt;/script&gt;
          &lt;link rel="shortcut icon" href="images/web.ico" /&gt;
          &lt;script type="text/javascript" src="js/another_script.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;Some text here&lt;/p&gt;
          &lt;p&gt;Some more text&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I know this is possible using for example <a href="http://jquery.com/" rel="nofollow">jQuery</a> or the <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow">Simple HTML DOM</a>, but I was wondering if I can achieve this without using any other external source.</p>