0

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?

trobrock
  • 46,549
  • 11
  • 40
  • 46

1 Answers1

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