public function saveHTML()
    {
        if ($this->isHtmlDocument()) {
            return $this->getDOMDocument()->saveHTML();
        } else {
            $doc = new \DOMDocument('1.0', 'UTF-8');
            $root = $doc->appendChild($doc->createElement('_root'));
            foreach ($this as $node) {
                $root->appendChild($doc->importNode($node, true));
            }
            $html = trim($doc->saveHTML());
            return preg_replace('@^<'.self::FRAGMENT_ROOT_TAGNAME.'[^>]*>|</'.self::FRAGMENT_ROOT_TAGNAME.'>$@', '', $html);
        }
    }
public function saveHTML()
    {
        if ($this->isHtmlDocument()) {
            return $this->getDOMDocument()->saveHTML();
        } else {
            $doc = new \DOMDocument('1.0', 'UTF-8');
            $root = $doc->appendChild($doc->createElement('_root'));
            foreach ($this as $node) {
                $root->appendChild($doc->importNode($node, true));
            }
            $html = trim($doc->saveHTML());
            return preg_replace('@^<'.self::FRAGMENT_ROOT_TAGNAME.'[^>]*>|</'.self::FRAGMENT_ROOT_TAGNAME.'>$@', '', $html);
        }
    }
public function saveHTML ( ) { if ( $ this -> isHtmlDocument ( ) ) { return $ this -> getDOMDocument ( ) -> saveHTML ( ) ; } else { $ doc = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ root = $ doc -> appendChild ( $ doc -> createElement ( '_root' ) ) ; foreach ( $ this as $ node ) { $ root -> appendChild ( $ doc -> importNode ( $ node , true ) ) ; } $ html = trim ( $ doc -> saveHTML ( ) ) ; return preg_replace ( '@^<' . self :: FRAGMENT_ROOT_TAGNAME . '[^>]*>|</' . self :: FRAGMENT_ROOT_TAGNAME . '>$@' , '' , $ html ) ; } }
Get the HTML code fragment of all elements and their contents.

If the first node contains a complete HTML document return only
the full code of this document.

@return string HTML code (fragment)
@api
Get the HTML code fragment of all elements and their contents .