PHP generated csv file is displaying £ for a UK pound sign (£) in Excel 2007

后端 未结 3 1876
温柔的废话
温柔的废话 2021-01-04 19:47

I\'m generating the csv file with the following header commands:

header(\"Content-type: text/csv; charset=utf-8; encoding=utf-8\");
header(\'Content-Disposit         


        
3条回答
  •  执笔经年
    2021-01-04 20:16

    Output 0xEF 0xBB 0xBF before emitting the CSV data. Don't forget to increase the content length header by 3 if you handle it.

    header('Content-type: text/csv;');
    header('Content-Length: ' + strlen($content) + 3);
    header('Content-disposition: attachment;filename=UK_order_' . date('Ymdhis') . '.csv');
    echo "\xef\xbb\xbf";
    echo $content;
    exit;
    

提交回复
热议问题