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

后端 未结 3 1877
温柔的废话
温柔的废话 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 19:58

    Use utf8_decode() - WORKED FOR ME

    0 讨论(0)
  • 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;
    
    0 讨论(0)
  • 2021-01-04 20:17
    header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
    header("Last-Modified: " . gmdate('D,d M Y H:i:s') . ' GMT');
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
    header('Content-Type: text/csv;');
    header("Content-Disposition: attachment; filename=".$savename);
    echo utf8_decode($csv_string);
    

    Posted as above by user769889 but I missed it with my frustrations with this v-annoying issue, all fixed now and working. Hope this helps someone...

    0 讨论(0)
提交回复
热议问题