I'm using XMLReader to parse a large XML file from a third party, file size is 1GB+. The XML file specifies the encoding as UTF8 (<?xml version="1.0" encoding="utf-8" ?>), although it isn't.
XMLReader throws an error because of the unknown encoding type, but not until it's already processed most of the file.
Exception message:
Input is not proper UTF-8, indicate encoding
I have determined that the real encoding of the file is ISO-8859-1, and it will work fine if I manually specify this when calling $reader->open().
The problem is that my script needs to parse unknown files from the database, so it needs to rely on the encoding type specified within the file. I need to find a way to parse any file regardless of its encoding, are there any suggestions for doing this?
iconvwhich can will do the checking without reading it into memory all at once. - deceze