CSV doesn't work with UTF-16 (and probably UTF-32) files #200
Description
When trying to read a UTF-16LE CSV file I encounter the error:
Notice: iconv(): Detected an incomplete multibyte character in input string in phpoffice/phpexcel/Classes/PHPExcel/Shared/String.php
After doing some digging it's because fgetCSV isn't paying attention to the fact that the file is UTF-16 and is splitting the file after the first byte of the commas.
Using "Cell1,Cell2" as sample data in the example below and [] to show where each 2 byte segment is, spaces for null bytes.
So [C ][e ][l ][l ][1 ][, ][C ][e ][l ][l ][2 ] gets split into "[C ][e ][l ][l ][1 ][," and " ][C ][e ][l ][l ][2 ]". Notice how when we try to convert the second cell we will be passing a string that will be read as "[ C][ e][ l][ l]" - hence the invalid character [ C].
A suggested solution is to set the locale to UTF-16; this doesn't work for me.
setlocale(LC_CTYPE, "en.UTF16");
Another potential workaround is to use a filter on the stream context to convert the file to UTF-8 as it is read from the file system and before it reaches fgetcsv (see http://www.php.net/manual/en/function.stream-filter-register.php).
Another possible solution is to read the file into memory and use str_getcsv (http://php.net/manual/en/function.str-getcsv.php).