I'm currently working on a project where I need to sequentially (256 byte) read a file that contains language information. So the string offset 0 starts the value for the language code 1, the offset 256 starts the value for the language code 2, ...
I don't exactly understand the encoding of the file though. The author says the file is encoded in Unicode, which is confirmed by opening it in Notepad++ which identifies it as UCS2 LE w/o BOM.
I'm trying to convert the text before splitting it into 255 byte long chunks like so:
$content = mb_convert_encoding($content, 'UTF-8', 'UCS-2LE');
This produces values like "Пользователь заблокирован
". I know this file is Russian, so this looks promising. However there are still values that appear incorrect:
"┐. ð¢ð░Ðüð¥Ðü ÐëðÁð╗ð¥Ðçð© ð£ð░"
Converting it with this code produces the same result:
$content = iconv('UTF-16', 'UTF-8', $content);
Here's the different encodings I've gotten from different sources:
Author:
"Unicode"
file -i <FILENAME>
"<FILENAME>: application/octet-stream; charset=binary"
mb_detect_encoding($content);
"UTF-8"
Notepad++:
"UCS-2 LE w/o BOM"
And here is a part of the file (extracted via vi
, newlines added for clarity):
^_^D>^D;^D=^DK^D9^D ^@0^D4^D@^D5^DA^D ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@
^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@
^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@
^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@
^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@
^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^@ ^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