I am trying to save a string of html into the nodeValue attribute of a DOMElement in PHP, but after I save the file with DOMDocument->saveHTMLFile the string of HTML is escaped and I can not figure out how to get the string not be saved as escaped text. Any ideas?
Asked
Active
Viewed 786 times
1 Answers
0
You should load that string of html with DOMDocument::loadHTML and append that to your node (appendChild).

Qwerty
- 1,732
- 1
- 13
- 18
-
This seems to be what I would be looking to do, after I parse the HTML string with loadHTML I am then trying to append it to the current element with this: $currElement->appendChild($html_dom_doc->documentElement) But I am getting an exception: Fatal error: Uncaught exception 'DOMException' with message 'Wrong Document Error' – trobrock Feb 15 '10 at 03:36
-
You can use importNode() method: http://en.php.net/manual/en/domdocument.importnode.php Also, PHP's DOM has non-standard appendXML() method, it looks exactly what you need (not sure it will accept HTML, though). Link with example: http://en.php.net/manual/en/domdocumentfragment.appendxml.php – Qwerty Feb 15 '10 at 03:55
text
) and being put into the nodeValue attribute of a DOMElement object and it is appearing in the file as: <p>text</p> – trobrock Feb 15 '10 at 03:14