How to Export UTF-8 CSV File in PHP
I had problems with displaying UTF-8 characters in my exported CSV files. Unlike LibreOffice Calc and Google Docs, this happened on only MS Excel. Here is a small hack:
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($str) ."; ");
header("Content-Disposition: attachment; filename=\"ourfilename.csv\"; ");
header("Content-Type: application/vnd.ms-excel");
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $str;
Add new comment