$data = [
'Товар 1;some;3',
'Товар 2;anather;6',
'Товар 3;test;9'
];
header('Content-Type: text/csv');
header('Content-disposition: attachment;filename=data.csv');
foreach ($data as $row) {
echo $row, PHP_EOL;
}
header('Content-Encoding: UTF-8');
header('Content-Type: text/csv; charset=utf-8' );
header(sprintf( 'Content-Disposition: attachment; filename=data.csv' ) );
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
$df = fopen( 'php://output', 'w' );
//This line is important:
fputs( $df, "\xEF\xBB\xBF" ); // UTF-8 BOM !!!!!
foreach ( $data as $row ) {
fputcsv( $df, $row , ';');
}
fclose($df);