<p>How to create a DOM from a User's input in PHP5?</p>

[{'answer_id': 78465, 'author': 'Adam Wright', 'author_id': 1200, 'author_profile': 'https://Stackoverflow.com/users/1200', 'pm_score': 2, 'selected': False, 'text': '<p>I would use the DOM API that has been part of the core since 5. For an XML string $xml, you can build a DOM object with</p>\n\n<pre><code>$dom = new DOMDocument();\n$dom-&gt;loadXML($xml);\n</code></pre>\n\n<p>Manipulate it with the rest of the DOM API, defined at <a href="http://uk.php.net/DOM" rel="nofollow noreferrer">http://uk.php.net/DOM</a></p>\n'}, {'answer_id': 89750, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>And when you need to inject it back into some other DOM (like your HTML page) you can export it again using the $dom->saveXML() method. The problem however is that it also exports an xml header (it\'s even worse for the saveHTML version). To get rid of that use this:</p>\n\n<pre><code>$xml = $dom-&gt;saveXML();\n$xml = substr( $xml, strlen( "&lt;?xml version=\\"1.0\\"?&gt;" ) );\n</code></pre>\n'}, {'answer_id': 97408, 'author': 'troelskn', 'author_id': 18180, 'author_profile': 'https://Stackoverflow.com/users/18180', 'pm_score': 0, 'selected': False, 'text': '<p>If the input is HTML, use the loadHTML method. Be ware that the input has to be valid code, so you might want to pipe it through <a href="http://docs.php.net/manual/en/book.tidy.php" rel="nofollow noreferrer">html tidy</a> first.</p>\n'}]
['https://Stackoverflow.com/questions/78447', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12854/']