How can I output a UTF-8 CSV in PHP that Excel will read properly?

后端 未结 30 2791
半阙折子戏
半阙折子戏 2020-11-22 06:08

I\'ve got this very simple thing that just outputs some stuff in CSV format, but it\'s got to be UTF-8. I open this file in TextEdit or TextMate or Dreamweaver and it displa

30条回答
  •  自闭症患者
    2020-11-22 06:29

    As I investigated and I found that UTF-8 is not working well on MAC and Windows so I tried with Windows-1252 , it supports well on both of them but you must select type of encoding on ubuntu. Here is my code$valueToWrite = mb_convert_encoding($value, 'Windows-1252');

    $response->headers->set('Content-Type', $mime . '; charset=Windows-1252');
        $response->headers->set('Pragma', 'public');
        $response->headers->set('Content-Endcoding','Windows-1252');
        $response->headers->set('Cache-Control', 'maxage=1');
        $response->headers->set('Content-Disposition', $dispositionHeader);
        echo "\xEF\xBB\xBF"; // UTF-8 BOM
    

提交回复
热议问题