title: PHP - DOMDocument - need to change/replace an existing HTML tag w/ a new one
body: <p>I'm trying to change all <code>&lt;P&gt;</code> tags in a document to <code>&lt;DIV&gt;</code>.  This is what I've come up with, but it doesn't seem to work:</p>
  
  <pre><code>$dom = new DOMDocument;
  $dom-&gt;loadHTML($htmlfile_data);
  
  foreach( $dom-&gt;getElementsByTagName("p") as $pnode ) {
      $divnode-&gt;createElement("div");
      $divnode-&gt;nodeValue = $pnode-&gt;nodeValue;
      $pnode-&gt;appendChild($divnode);
      $pnode-&gt;parentNode-&gt;removeChild($pnode);
  }
  </code></pre>
  
  <p>This is the result I want:</p>
  
  <p>Before:</p>
  
  <pre><code>&lt;p&gt;Some text here&lt;/p&gt;
  </code></pre>
  
  <p>After:</p>
  
  <pre><code>&lt;div&gt;Some text here&lt;/div&gt;
  </code></pre>