0

I had a trouble exporting UTF-8 data to Excel, but now it's ok, because I've found this:

Microsoft Excel mangles Diacritics in .csv files?

Look at this line:

echo chr(255) . chr(254) . mb_convert_encoding($csv, 'UTF-16LE', 'UTF-8');

When I remove chr(255) . chr(254) at the beginning the Excel can't display UTF-8 data normally, so can't the browser.

It's not a problem of course, I would just like to know, why those chr(255) and chr(254) are essential.

Community
  • 1
  • 1
noname
  • 551
  • 9
  • 29

2 Answers2

1

Excel and PHP differ in their opinion of BOM (byte order mark) to indicate this character encoding. With chr(255).chr(254), you are manually forcing the output to be what Excel desires. See http://nl.wikipedia.org/wiki/Endianness

matthiasmullie
  • 2,063
  • 15
  • 17
1

It seems, that Excel requires the Byte Order Mark (BOM). The BOM is always at the beginning of a file and either FFFE or FEFF. It describes in which order the separate bytes of a multibyte-character appears (lets say "forward" or "backward"). Usually its strongly recommended to omit it, but it seems, that excel uses it to determine the file encoding.

KingCrunch
  • 128,817
  • 21
  • 151
  • 173