【发布时间】:2017-01-11 19:20:19
【问题描述】:
我正在开发一个导出简单 CSV 的项目。到目前为止,只要我使用英文字符,我的代码就可以工作并生成 CSV。
一些列名将使用法语并希望能够对其进行编码。
这是我所拥有的:
<?php
// open the file "demosaved.csv" for writing
$file = fopen('myfrench-export.csv', 'w');
// save the column headers
fputcsv($file, array('Question', 'Réponse 1/4', 'Réponse 2/4', 'Réponse 3/4', 'Réponse 4/4', 'Total completé', 'Total non-completé', 'Total cumulatif'));
// Sample data. This can be fetched from mysql too
$data = array(
array('Data 11', 'Data 12', 'Data 13', 'Data 14', 'Data 15'),
array('Data 21', 'Data 22', 'Data 23', 'Data 24', 'Data 25'),
array('Data 31', 'Data 32', 'Data 33', 'Data 34', 'Data 35'),
array('Data 41', 'Data 42', 'Data 43', 'Data 44', 'Data 45'),
array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55'),
array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55'),
array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55'),
array('Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55'),
);
// save each row of the data
foreach ($data as $row)
{
fputcsv($file, $row);
}
// Close the file
fclose($file); ?>
【问题讨论】:
-
是什么导致法语文本被编码为 "Réponse 3/4" 而不是 "Réponse 3/4" ,以及如何解决?
-
您在什么操作系统上编写代码?你的代码在什么操作系统上运行?
-
我在 Windows 10 上编写代码,代码在 Xampp 上本地运行,在 Wordpress 应用程序上的 Azure 上远程运行。不过这有关系吗?
-
使用
mb_convert_encoding( $string, 'HTML-ENTITIES','utf-8' );为我工作;而utf8_decode并没有做到这一点。