In PHP it is easy to pass back an json objects by using the json_encode(). However is there an XML equivalent of this?
json_encode()
This works for me in most cases:
$str = htmlentities($str , ENT_XML1);
Docs: http://php.net/manual/en/function.htmlentities.php