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.

6 Comments

  1. Rafael

    Helped me! Thanks!

  2. amitesh

    Thanks Buddy…dis issue has wasted 6 hours of my time…

    thankssss a lottttttttttttttttt :)

  3. Bas

    I nearly cried of anger, Now I am crying of joy !

  4. Robert

    You are the boss :)

  5. Moynul

    Not working Man :(

  6. Henry

    Thank you so much. You made me get sleep tonight.

Leave a comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>