简体   繁体   English

csv 导出中的 æøå

[英]æøå in csv export

I'm trying to export some data into an CSV file i can download.我正在尝试将一些数据导出到我可以下载的 CSV 文件中。

if im hitting my API in postman the data looks fine like:如果我在邮递员中点击我的 API,数据看起来很好:

Notat,Vare,Type,Størrelse,Tekst,Antal,Pris,Rabatprocent,Totalbeløb,Fakturerbar,"Lever nu",Faktureret,Lagersted,Placering,Lagerstyring
,,,,"Fadol 0,5 - 6 stk. ",4,,"0,00",1000,Checked,0,"0,00",,,Intet
,,,,"Classic 0,5",34,,"0,00",1700,Checked,0,"0,00",,,Intet
,,,,"Classic 0,5 - 6 stk ",3,,"0,00",750,Checked,0,"0,00",,,Intet
,,,,"Grimbergen 0,3",6,,"0,00",240,Checked,0,"0,00",,,Intet
,,,,"Nordic flaske ",0,,"0,00",0,Checked,0,"0,00",,,Intet
,,,,Kildevand,109,,"0,00",2160,Checked,0,"0,00",,,Intet
,,,,"Smirnoff 6 stk",0,,"0,00",0,Checked,0,"0,00",,,Intet
,,,,"Sæson 0,3",2,,"0,00",80,Checked,0,"0,00",,,Intet
,,,,"Sodavand 0,3",5,,"0,00",150,Checked,0,"0,00",,,Intet
,,,,"Sodavand 0,5",102,,"0,00",4040,Checked,0,"0,00",,,Intet
,,,,"Fadøl 0,5",20,,"0,00",1000,Checked,0,"0,00",,,Intet
,,,,"Kop varme drikke",17,,"0,00",255,Checked,0,"0,00",,,Intet

But when i open the CSV file after downloading it will show Størrelse as Størrelse.但是当我下载后打开 CSV 文件时,它会将 Størrelse 显示为 Størrelse。 Så it works fine in postman but not in the actual CSV file. Så 它在邮递员中工作正常,但在实际的 CSV 文件中无效。 someone can point me in the right direction for where my problem is?有人可以指出我的问题所在的正确方向吗?

Here is my code that creates the export:这是我创建导出的代码:

//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));

depends on encoding type.取决于编码类型。 I got similar issue with csv file.I converted the row to "ISO-8859-1" ( for german characters) .我在 csv 文件中遇到了类似的问题。我将该行转换为 "ISO-8859-1" (for German characters) 。

 iconv(mb_detect_encoding($text), "ISO-8859-1", $text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM