Escaping special characters in XML with PHP
I'm reading a XML document with invalid characters like "&" that needs to be converted into valid XML entities. How can I accomplish this in PHP?

I've tried using htmlentities(), but obviously this ruins much of the other formatting.
Escaping special characters in XML with PHP
===

I'm reading a XML document with invalid characters like "&" that needs to be converted into valid XML entities. How can I accomplish this in PHP?

I've tried using htmlentities(), but obviously this ruins much of the other formatting.