Downloading data in excel format with PHP And Unicode

public function _exportToCSV($status){
$columnHeader = "";

$setData = '';

$findAll = ImportUsers::model()->findAll("status = $status");
if(!empty($findAll)){
foreach($findAll as $objData){
$rowData = '';
$value = '"' . $objData->title1 . '"' . "\t";
$value .= '"' . $objData->title2 . '"' . "\t";
$value .= '"' . $objData->title3 . '"' . "\t";

$rowData .= $value;
$setData .= trim($rowData) . "\n";
}
}
$fileName = 'output.csv';
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename = $fileName");
header('Content-Transfer-Encoding: binary');
header("Pragma: no-cache");
header("Expires: 0");

echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $setData . "\n");

exit();
}

Enjoy.

--

--

I am a Back-End Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store