Posts Tagged ‘SimpleXML’

Beware of the & (ampersand) character when parsing XML using PHP’s SimpleXML

Sunday, November 15th, 2009

If you are getting errors like “parser error : EntityRef: expecting ‘;’” when trying to parse some XML using SimpleXML, it could be because your XML file or string contains an & character. Do the following to remedy the situation:

$correct_xml = str_replace('&','&',$problem_xml);