PHP XML encoding

I meet a same encoding problem using DOMDocument::load XML described at

In short, if the XML has encoding=”UTF-8″, it will be parsed properly. In my case, the XML has encoding=”windows-1252″, but it has been changed to “UTF-8”. For example, “Schütze” is changed to “Schütze”. My guess is that DOMDocument::load only recognizes  “UTF-8”, otherwise it changes other encoding to “UTF-8”.

My solution is “iconv(“UTF-8″,”windows-1252″,$str)” which changes it back to original encoding. This solution assumes you know the original encoding.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s