title: How to stop PHP DOM from auto-escaping character references?
body: <p>...or how to do it another way?</p>
  
  <p>I'm creating a select box using <a href="http://www.php.net/manual/en/class.domdocument.php" rel="nofollow">DOMDocument</a>.</p>
  
  <pre><code>$field = $this-&gt;dom-&gt;createElement('select');
  $optgroup = $this-&gt;dom-&gt;createElement('optgroup');
  
  foreach($options as $v) {
     $option = $this-&gt;dom-&gt;createElement('option');
     $option-&gt;setAttribute('value', $v);
     $option-&gt;appendChild($this-&gt;dom-&gt;createTextNode($v));
  
     $optgroup-&gt;appendChild($option);
  }
  
  $field-&gt;appendChild($optgroup);
  </code></pre>
  
  <p>Where <code>$options</code> is an array of character references pre-loaded from an icon font:</p>
  
  <pre><code>array('&amp;#33;', '&amp;#34;', '&amp;#35;', '&amp;#36;', ...);
  </code></pre>
  
  <p>I need my output to look like this:</p>
  
  <pre><code>&lt;select&gt;
    &lt;optgroup&gt;
      &lt;option value="&amp;#33;"&gt;&amp;#33;&lt;/option&gt;
      &lt;option value="&amp;#34;"&gt;&amp;#34;&lt;/option&gt;
      &lt;option value="&amp;#35;"&gt;&amp;#35;&lt;/option&gt;
      ...
    &lt;/optgroup&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>However, using the DOM methods, it auto escapes all the character references:</p>
  
  <pre><code>&lt;option value="&amp;amp;#33;"&gt;&amp;amp;#33;&lt;/option&gt;
  </code></pre>
  
  <p>How can I prevent that from happening?</p>
  
  <p><strong>NOTE:</strong> <a href="http://php.net/manual/en/domdocument.createentityreference.php" rel="nofollow"><code>createEntityReference</code></a> does not work for this as that method only supports entity references and not character references. Using it causes a fatal error for 'Invalid character error'.</p>