Categories

Archives

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

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;

Comments are closed.