Solution To Output a UTF-8 CSV in PHP That Excel Will Read Properly

Excel doesn't support UTF-8. You have to encode your UTF-8 text into UCS-2LE. It is very simple to change the encoding in PHP. You can use following PHP inbuilt function to covert encoding from utf8 to ucs-2le.

mb_convert_encoding($output, 'UCS-2LE', 'UTF-8');

Open the CSV with excel, it will display the special characters properly. It saved a lot of time for me at-least.

Let me know if it helped for you guys as well?

Comments

Popular Posts