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

后端 未结 30 2843
半阙折子戏
半阙折子戏 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:30

    //convert UTF-8 file without BOM to UTF-16LE for excel on mac
    $fileUtf8String = file_get_contents("file.ext");
    file_put_contents("file.ext", "\xFF\xFE" . mb_convert_encoding($fileUtf8String, "UTF-16LE", "UTF-8"));
    

提交回复
热议问题