CSV ファイルを受け取り、すべての行を配列に読み込む単純なスクリプトがあります。次に、最初の行の各列 (私の場合はアンケートの質問が含まれています) を循環し、それらを印刷します。調査はフランス語で行われ、質問の最初の文字が特殊文字 (é、ê、ç など) である場合は常に、fgetcsv は単純にそれを省略します。
値の中間にある特殊文字は、それらが最初の文字である場合にのみ影響を受けません。
これをデバッグしようとしましたが、困惑しています。私はファイルの内容で var_dump を実行しましたが、文字は間違いなくそこにあります:
var_dump(utf8_encode(file_get_contents($_FILES['csv_file']['tmp_name'])));
そして、ここに私のコードがあります:
if(file_exists($_FILES['csv_file']['tmp_name']) && $csv = fopen($_FILES['csv_file']['tmp_name'], "r"))
{
$csv_arr = array();
//Populate an array with all the cells of the CSV file
while(!feof($csv))
{
$csv_arr[] = fgetcsv($csv);
}
//Close the file, no longer needed
fclose($csv);
// This should cycle through the cells of the first row (questions)
foreach($csv_arr[0] as $question)
{
echo utf8_encode($question) . "<br />";
}
}