Convert UTF-16LE to UTF-8 in php

Viewed 38967

I use iconv php function but some characters doesn't convert correctly:

...
$s = iconv('UTF-16', 'UTF-8', $s);
...
$s = iconv('UTF-16//IGNORE', 'UTF-8', $s);
...
$s = iconv('UTF-16LE', 'UTF-8', $s);
...
$s = iconv('UTF-16LE//IGNORE', 'UTF-8', $s);
...

I also try mb_convert_encoding function but can't solve my problem.

A sample text file: 9px.ir/utf8-16LE.rar

2 Answers

You should use //TRANSLIT or //IGNORE in the second argument of the function, which represents the output charset. You used it by mistake in the first argument.

Please, see more details and examples at https://www.php.net/manual/en/function.iconv.php

Related