PHP SimpleXml Parser Error

If you use PHP with SimpleXml to parse xml you may run across a strange issue where SimpleXml fails to parse perfectly formatted xml. You'll likley get an error like this

Warning: simplexml_load_string() [function.simplexml-load-string]:

Entity: line 1: parser error : AttValue: " or ' expected

Chances are the PHP server has 'magic quotes' turned on. To get around the issue, add a strip slashes command to the xml string before parsing it. So your php would change from

 

$xml = simplexml_load_string($xmlstr); 

 to

$xml = simplexml_load_string(stripslashes($page));

 Hope that helps someone, frustrating bug to track down.


2 Comments:

  1. Rafael

    Helped me! Thanks!

  2. amitesh

    Thanks Buddy...dis issue has wasted 6 hours of my time...
    thankssss a lottttttttttttttttt :)


Leave a comment






wrap code blocks in <code> </code> tags