How to get html code of DOMElement node? [duplicate] How to get html code of DOMElement node? [duplicate] php php

How to get html code of DOMElement node? [duplicate]


Use the optional argument to DOMDocument::saveHTML: this says "output this element only".

return $node->ownerDocument->saveHTML($node);

Note that the argument is only available from PHP 5.3.6. Before that, you need to use DOMDocument::saveXML instead. The results may be slightly different. Also, if you already have a reference to the document, you can just do this:

$doc->saveHTML($node);