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.

No comments yet.


Leave a comment

Name: (required)

Email: (required)

URL:

Captcha test: (required)
Comments: (required)

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