I have a Domnodelist of html nodes, which I would like to echo out including their html tags so that I can apply a regex.When I do:
foreach ($nodeList as $key => $node) {
echo $node->nodeValue;
}
I get only the text portions of the nodes, without html tags.
when I try:
echo $node->saveHTML;
I get the error: Undefined property: DOMElement::$saveHTML
How can I do this?
Thanks in advance,
Bill
saveHTMLis a function, so you need to call it (you were missing the parens). It’s also part ofDOMDocument; the node will be passed in as a parameter.So the correct form is:
Important note:
saveHTMLonly supports a parameter from PHP 5.3.6 onwards.However, people use
DOMDocumentspecifically so that they can process it without resorting to regular expressions. It seems that here you are trying to do the opposite. If so, reconsider your approach — regular expressions are a hacky way to process HTML that will bring trouble the second you decide to do anything that is not totally trivial.