Вывод в excel.csv дает странную ошибку - PullRequest
0 голосов
/ 18 сентября 2018

Я просто не могу заставить ÆØÅ давать мне правильные символы.

Если я открою 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));
...