title: How to print unescaped HTML with PHP DOMDocument
body: <p>I have a simple, locally-run app in JQuery &amp; PHP that allows a user to open a file, rearrange it's DOM elements, and then generate a new file with the rearranged elements. The problem is that the PHP DOMDocument is printing escaped HTML. I need to print the contents of <code>#newfile</code>, received by the POST as <code>$content</code>, as unescaped HTML.</p>
  
  <p>The POST function looks like this: </p>
  
  <pre><code>   $("#submit").click(function() {
       var str = $('#newfile').html();
       $.post("generate.php", { content: str} );
    });
  </code></pre>
  
  <p>The generate.php file looks like this: </p>
  
  <pre><code> &lt;?php
   $content = $_POST['content'];
  
   $doc = new DOMDocument('1.0');
  
   $doc-&gt;formatOutput = true;
  
   $root = $doc-&gt;createElement('html');
   $root = $doc-&gt;appendChild($root);
  
   $head = $doc-&gt;createElement('head');
   $head = $root-&gt;appendChild($head);
  
   $body = $doc-&gt;createElement('body');
   $body = $root-&gt;appendChild($body);
  
   $element = $doc-&gt;createElement('div', $content);
   $element = $body-&gt;appendChild($element);
  
   echo 'Wrote: ' . $doc-&gt;saveHTMLFile("output/test.html") . ' bytes';
  
   ?&gt; 
  </code></pre>
  
  <p>The output is currently a well-formatted HTML document, but the content I need is escaped:</p>
  
  <pre><code> &lt;html&gt;
   &lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;&lt;/head&gt;
   &lt;body&gt;&lt;div&gt;
          &amp;lt;div class="page"&amp;gt;
              &amp;lt;h3&amp;gt;1. Definition&amp;lt;/h3&amp;gt;
              &amp;lt;div id="definition" class="output ui-droppable"&amp;gt;
              &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
   &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>How do I print $content as unescaped HTML?</p>