1

I'm getting different results in php when using iconv vs mb_convert_encoding when trying to convert UTF-8 to UTF-16.

echo iconv('UTF-8', 'UTF-16', 'test'); // ��test

echo mb_convert_encoding('test', 'UTF-16', 'UTF-8'); // test

Notice the two � symbols at the beginning of the beginning of the iconv() output.

Any thoughts on why mb_convert_encoding isn't doing the same?

Thanks.

AnthonyRyan
  • 153
  • 1
  • 7

1 Answers1

2

iconv adds a BOM at the begging of the output string. So for converting string, you probably want to use mb_convert_encoding. iconv can be more useful for files.

Dean Fenster
  • 2,345
  • 1
  • 18
  • 27
  • Thank you. If I prepend the UTF-16 BOM characters to the mb_convert_encoding() string I get the exact same output as iconv(). – AnthonyRyan Apr 21 '17 at 13:21