header("Content-Encoding: UTF-8");
header("Content-type: application/csv");
header("Content-disposition: attachment; filename=file.csv");
$out = fopen("php://output", "w");
// add BOM specification for open in excel
fputs($out, chr(239) . chr(187) . chr(191));
// add rows from data
foreach ($data as $row) {
fputcsv($out, $row, ";");
}
fclose($out);