php将带有重音符号的数据导出到csv中

php将带有重音符号的数据导出到csv中,php,csv,character-encoding,Php,Csv,Character Encoding,我有以下创建csv文件的代码: $data=array(); array_push($data,"Société"); //word with french accent header('Content-Type:text/csv; charset=UTF-8'); header('Content-Disposition: attachment; filename="test.csv"'); $fp = fopen('php://output', 'w'); foreach ( $dat

我有以下创建csv文件的代码:

$data=array();
array_push($data,"Société"); //word with french accent


header('Content-Type:text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="test.csv"');


$fp = fopen('php://output', 'w');
foreach ( $data as $line ) {
    $val = explode(",", $line);
    fputcsv($fp, array_map('utf8_decode',array_values($val)), ',', '"');
}
fclose($fp);
但是,当我打开csv文件时,字符
é
被问号
替换


如何解决这个问题有什么帮助吗?

不久前,我遇到了一个类似的问题,我通过在任何csv行之前添加3字节UTF8表示法解决了这个问题:

header('Content-Type: application/x-download');
header("Content-Transfer-Encoding: binary");
header('Content-Disposition: attachment; filename="export-'.time().'.csv"');

echo chr(0xEF);
echo chr(0xBB);
echo chr(0xBF);

是否尝试删除数组映射调用中的“utf8\u decode”参数

如果对UTF-8字符串调用函数“utf8_decode”,它将在不支持重音的拉丁-1编码下返回该函数

请参阅utf8_decode>PHP文档


祝你好运。

我在字符串中使用了
UTF-8
字符。我换了

array_push($data,"Société"); //word with french accent


我已将该行替换为
fputcsv($fp,$val)array_push($data,"Soci\xc3\xa9t\xc3\xa9"); //word with french accent