dom.php 381 B

12345678910111213141516
  1. <?php
  2. function encode_document($text) {
  3. libxml_use_internal_errors(true);
  4. $document = new DOMDocument();
  5. $document->loadHTML("<?xml encoding=\"UTF-8\">" . $text);
  6. foreach ($document->childNodes as $node) {
  7. if ($node->nodeType === XML_PI_NODE)
  8. $document->removeChild($node);
  9. };
  10. $document->encoding = "UTF-8";
  11. return $document;
  12. };
  13. ?>