title: Change outerHTML of a php DOMElement?
body: <p>How do I change the <strong>outerHtml</strong> of an element using PHP DomDocument class? Make sure, no third party library is used such as Simple PHP Dom or else.</p>
  
  <p>For example: 
  I want to do something like this.</p>
  
  <pre><code>$dom = new DOMDocument;
  $dom-&gt;loadHTML($html);  
  $tag = $dom-&gt;getElementsByTagName('h3');
  foreach ($tag as $e) {
   $e-&gt;outerHTML = '&lt;h5&gt;Hello World&lt;/h5&gt;';
  }
  
  libxml_clear_errors();
  $html = $dom-&gt;saveHTML();
  echo $html;
  </code></pre>
  
  <p>And the output should be like this:</p>
  
  <pre><code>Old Output: &lt;h3&gt;Hello World&lt;/h3&gt;
  But I need this new output: &lt;p&gt;Hello World&lt;/p&gt;
  </code></pre>