title: How do I prevent Php's DOMDocument from encoding html entities?
body: <p>I have a function that replaces anchors' href attribute in a string using Php's DOMDocument.  Here's a snippet:</p>
  
  <pre><code>$doc        = new DOMDocument('1.0', 'UTF-8');
  $doc-&gt;loadHTML($text);
  $anchors    = $doc-&gt;getElementsByTagName('a');
  
  foreach($anchors as $a) {
      $a-&gt;setAttribute('href', 'http://google.com');
  }
  
  return $doc-&gt;saveHTML();
  </code></pre>
  
  <p>The problem is that loadHTML($text) surrounds the $text in doctype, html, body, etc. tags.  I tried working around this by doing this instead of loadHTML():</p>
  
  <pre><code>$doc        = new DOMDocument('1.0', 'UTF-8');
  $node       = $doc-&gt;createTextNode($text);
  $doc-&gt;appendChild($node);
  ...
  </code></pre>
  
  <p>Unfortunately, this encodes all the entities (anchors included).  Does anyone know how to turn this off? I've already thoroughly looked through the docs and tried hacking it, but can't figure it out.</p>
  
  <p>Thanks! :)</p>