私は非常に単純な CSV ファイル (約 500 行、14.5k) を配列に入れる必要があります。後で ID 列を他のデータ セットと照合する必要があります。
CSV は次のようになります。
id,mail,Plan
102,,Plan_Pay
1028,,Plan_Pay
1031,,Plan_Prom
1032,,Plan_Pay
1033,,Plan_Pay
1034,xxxxxx@gmail.com,Plan_Free
1035,xxxxxx@gmail.com,Plan_Free
1036,xxxxxx@gmail.com,Plan_Pay
1079,,Plan_Prom
109,,Plan_Pay
1166,xxxxxx@elid.com,Plan_Prom
12,xxxxxx@gmail.com,Plan_Pay
....
....
(on and on .. about 500 lines)
しかし、とにかくそれを解析しようとすると、空の配列が得られます。
私はparsecsv libで試しました
$csvf = 'id2.csv';
echo $csvf; // debug verify that path exists
$csv = new parseCSV();
$csv->auto($csvf);
print_r($csv->data);// results empty
また、バリアント
$csv = new parseCSV('id2.csv');
print_r($csv->data);// results empty
私も試しました( php.net から):
if ( !function_exists('fgetcsv') ) echo 'Server too old ... we need to check.';// but it is ok
function csv_to_array($filename, $delimiter=',')
{
if(!file_exists($filename) || !is_readable($filename)){
$data = array();
$data[] = 'no file'; // debug -verify there is file..
// echo 'no file'; // debug -verify there is file..
// return FALSE;
}
$header = NULL;
$data = array();
if (($handle = fopen($filename, 'r')) !== FALSE)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
{
if(!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
$csv = csv_to_array($csvf);
echo $csvf; // debug verify correct path
print_r($csv);// results empty
"id2.csv"
相対 ( ) 、絶対 ( ) など、すべてのパスの組み合わせを試し"http://path.to/id2.csv"
ましたが、結果はすべて同じです。
私の質問は: ファイル自体に何か問題があるのでしょうか? *.CSV は非常にシンプルな形式で、非常に小さなファイル (約 500 行) です。エンコーディングの問題でしょうか (bom なしの UTF-8 です)。それともサーバーの問題ですか?それとも、私はそれをすべて間違っていますか?? (今まで、目に見えるエラーはどこにもありませんでした)