So I have a PHP Script thats parsing an XML Response from Google Analytics. It has been working for a few weeks, but today I’ve been getting this warning, and simple xml load string is not converting the xml response into a simplexml object.
Message: simplexml_load_string():
Entity: line 743: parser error :
Entity ‘acirc’ not defined
I have tried utf8_encoding the response before I pass it into simplexml_load_string, but it isn’t working. I believe that acirc is an encoded symbol, and that this symbol is screwing up the parser somehow?
I get the warning above twice, and then I get this one twice also:
Message: simplexml_load_string():
Entity: line 743: parser error :
Entity ‘cent’ not defined
Any advice would be a huge help, thanks!
Thanks for the comment Marc, I have tried this:
$xml = simplexml_load_string(htmlspecialchars_decode($response_body));
And I get an interesting error, but the xml object is still empty:
Entity: line 743: parser error : Input
is not proper UTF-8, indicate encoding
! Bytes: 0x84 0x26 0x63 0x65
The string you want to create a SimpleXMLElement from is not valid XML. The simple xml function can only deal with valid XML. For anything invalid you’ll get errors and no element instead. As you played around with the data already you’ve seen some of the errors.
The first error is just the information that your XML has undefined entities. The second error you find especially interesting for a reason I don’t understand is because you really ditched the string into some encoding nirvana. So then even the string isn’t properly encoded any longer for simplexml to deal with.
If that response you get should really be valid XML, then file a bugreport with google, make them fix their broken output and then your issue should be solved.
Edit:
You copy and paste it from the browser? If so try running
html_entity_decode()on it before loading it as XML. Probably you’re not loading XML but HTML. Better useDomDocumentand theloadHTMLfunction instead, no need to decode anything then.