in PHP, how to add a tag within an existing one?
<p>I'm trying to add a <code>&lt;style&gt;</code> tag within an existing <code>&lt;head&gt;</code> tag.  I can't seem to figure out how to do this for some reason; this is what I've come up with so far (by the way, the existing <code>&lt;head&gt;</code> tag is empty):</p>

<pre><code>$dom = new DOMDocument;
$dom-&gt;loadHTML($htmlfile_data);
$xpath = new DOMXPath($dom);
$headnode = $xpath-&gt;query('//head'); // i assume this is an array?
$stylenode = $dom-&gt;createElement('style');
$headnode[0]-&gt;appendChild($stylenode);

$htmlfile_data = $dom-&gt;saveHTML();
</code></pre>

<p>Basically I want the output to be:</p>

<p>before:</p>

<pre><code>&lt;head&gt;&lt;/head&gt;
</code></pre>

<p>after:</p>

<pre><code>&lt;head&gt;&lt;style&gt;&lt;/style&gt;&lt;/head&gt;
</code></pre>
