You are extracting data from multiple channels, so you cannot depend on all the channels that you use with the same character encoding.
The XML feeds are supposed to report which encoding they use in the XML preamble, and the server should send headers containing the character encoding that the file uses, but they are not necessary, and if they are not specific, to be exact.
You can use mb_detect_encoding to try to figure out which encoding you use for parsing, but again, which is not 100% accurate.
So, if your goal normalizes all the channels that you are processing into the same encoding (I assume UTF 8), your options should look at the XML preamble, headers (if the corresponding one is sent) and the result of mb_detect_encoding to determine the encoding. If all of the above is consistent with you, probably (but not necessarily), there is a good idea what the encoding of the file is and what you need to do to convert it. If there is any disagreement between any of these methods, then you will have to decide for yourself what actions to take.
In short, welcome to Harset Hell. How do you like it?
source share