How to handle special characters with XMLReader in PHP
I am having problems parsing an XML file which contains special characters. I am using the built in XMLreader in PHP. All XML records are processed fine, until one of the values contain a special character, then I get the following error:
Warning: XMLReader::read(): An Error Occured while reading in...
Once I remove the character it parses fine, but I need to be able to parse special characters and write them into my database.
You need to be sure which encoding is used by your PHP-Interpreter and the encoding used in the xml-file.
Make sure, that both points are using the same (recommended UTF-8), then it should work.
This is my XML header: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
When I open the XML file using Firefox, the special characters show as "black diamond with white question mark". When I use "us-ascii" as my encoding it shows up correctly in firefox. So which encoding should I use?
You said it should work when I make both UTF-8. If my XML encoding is left like above, how do I make sure my PHP XMLreader is interpreting it in UTF8?
I had a look at the setlocale, but can't get it working.
See my test XML file attached. I am trying to parse it with the code in my initial post.
Make sure, that both points are using the same (recommended UTF-8), then it should work.
http://www.php.net/setlocale