XML error at ampersand (&)
&
in XML starts an entity. As you haven't defined an entity &WhateverIsAfterThat
an error is thrown. You should escape it with &
.
$string = str_replace('&', '&', $string);
How do I escape ampersands in XML
To escape the other reserved characters:
function xmlEscape($string) { return str_replace(array('&', '<', '>', '\'', '"'), array('&', '<', '>', ''', '"'), $string);}
You need to either turn &
into its entity &
, or wrap the contents in CDATA tags.
If you choose the entity route, there are additional characters you need to turn into entities:
> >< <' '" "
Background: Beware of the ampersand when using XML
Wikipedia: List of XML character entity references