我似乎无法让ÆØÅ
给我正确的字符。
如果我打开Excel,然后从数据导入并选择UTF-8,它将正确显示。但是我不能要求用户打开excel并执行此操作,那么如何使Excel第一次正确打开文件?
//Give our CSV file a name.
$csvFileName = 'example.csv';
//Open file pointer.
$fp = fopen('php://output', 'w');
//Loop through the associative array.
foreach($sortedData as $row){
//Write the row to the CSV file.
fputcsv($fp, $row,";");
}
//Finally, close the file pointer.
fclose($fp);
$response = $response->withHeader('Content-Type', 'text/csv; charset=utf-8');
$response = $response->withHeader('Content-Disposition', 'attachment; filename="file.csv"');
$stream = fopen('php://memory', 'r+');
return $response->withBody(new \Slim\Http\Stream($stream));