Recently, I needed to take an Excel CSV file, read it using PHP, loop over each row, and insert each row into a MySQL database. The database was configured to support UTF-8 characters. Unfortunately, the Excel CSV file was not UTF-8-encoded. To figure to the file’s encoding, I opened it in Notepad++ which told me that it was encoded as UCS-2 Little Endian.
I then downloaded iconv which is available for both Unix and Windows and tried to convert the file’s encoding from UCS-2 to UTF-8 which seemed to work. The command I ran was
C:Program Files (x86)GnuWin32bin>iconv.exe -f UCS-2LE -t utf-8 ucs-2-source-file.csv >utf-8-output-file.csv
Opening the converted filed in Notepad++ reveals that it actually did convert the file’s encoding to UTF-8.
Note: I also tried iconv setting the original encoding to “utf-16” instead of “ucs-2le” and that appeared to work too.