DOMElement object to HTML

28/11/2009

Here is a quick way to get HTML from a DOMElement in PHP

function getHtmlFromDomElement($element) {
    $doc = new DOMDocument();
    foreach($element->childNodes as $child)
    {
        $doc->appendChild($doc->importNode($child, true));
    }
    return $doc->saveHTML();
}

There is 1 comment in this article:

  1. 24/04/2010BONZaI say:

    Works well.
    Thanks !

Write a comment: