loadHTML('
Para 1
Para 2
Para 1
Para 2
'); * * // Set inner HTML * $elem->setInnerHtml('FiveFilters.org'); * assert($elem->getInnerHtml() === 'FiveFilters.org'); * * // print document (with our changes) * echo $doc->saveXML(); * ``` */ final class JSLikeHTMLElement extends \DOMElement { /** * Sets inner HTML. */ public function setInnerHtml(string $value): void { // first, empty the element if (isset($this->childNodes)) { for ($x = $this->childNodes->length - 1; $x >= 0; --$x) { $this->removeChild($this->childNodes->item($x)); } } // $value holds our new inner HTML $value = trim($value); if (empty($value)) { return; } // ensure bad entity won't generate warning $previousError = libxml_use_internal_errors(true); $f = $this->ownerDocument->createDocumentFragment(); // appendXML() expects well-formed markup (XHTML) $result = $f->appendXML($value); if ($result) { if ($f->hasChildNodes()) { $this->appendChild($f); } } else { // $value is probably ill-formed $f = new \DOMDocument(); // Using