PHP iconv spits out gibberish when used on UTF-16LE

51 Views Asked by At

Im trying to decode UTF-16LE file to UTF-8 problem is I keep getting back kanji and I don't know what might be the cause. Code in question looks as follows

echo("before: ".$line);
$line = iconv('UTF-16LE', 'UTF-8', $line);
// $line = mb_convert_encoding($line, 'UTF-8', 'UTF-16');
echo("after: ".$line);  

where lines are read form file and tried to translate individualy, here is one such file

SŃSKA AZKA
asd ŹĆŻĆĄŚŃ
:61:020102C50,00NTRFNONREF//
PRZEODZĄCY
:86:010<00PRZYCHODZĄCY
<101900200001

when run the program returns this.

When i replace UTF-16LE with UTF-16 output looks a little better but it's still wrong

I have no idea what might be the cause of this. I am certain file is in UTF-16LE as I just created this test file. And when I put it into online UTF-16LE decoders they come out fine.

0

There are 0 best solutions below