From: Robert Kaiser Date: Thu, 15 Dec 2016 21:59:12 +0000 (+0100) Subject: replace workaround for HTML markup with a sane way of doing it, via loadHTML() X-Git-Url: https://git-public.kairo.at/?a=commitdiff_plain;h=a9a5a68a1cb685a6f441dd8d20339db29326b187;p=php-utility-classes.git replace workaround for HTML markup with a sane way of doing it, via loadHTML() --- diff --git a/classes/document.php-class b/classes/document.php-class index 3e39f0a..dbad743 100755 --- a/classes/document.php-class +++ b/classes/document.php-class @@ -299,8 +299,13 @@ class ExtendedDocument extends DOMDocument { public function appendHTMLMarkup($htmldata, $parentNode = null) { if (is_null($parentNode)) { $parentNode =& $this; } - // XXX: just a workaround for now! - $parentNode->appendChild($this->createCDATASection($htmldata)); + // Use loadHTML() to parse and turn the markup into proper HTML. + $tmpdoc = new ExtendedDocument; + // The XML line is needed to tell the parser that we need UTF-8 parsing. + $tmpdoc->loadHTML(''.$htmldata.''); + foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) { + $parentNode->appendChild($this->importNode($child, true)); + } } public function appendXMLMarkup($xmldata, $parentNode = null) {