我在這裏要做的是用我從csv文件中獲得的數據創建一個數組。我已經嘗試str_getcsv
,但它沒有正常工作。在PHP中導入CSV文件並將其更改爲二維數組
'Not Atribuited,"Agility Client","Servers AD","3 - Média","05/01/2015 09:13","3,0000000000","0","1"'
'Not Atribuited,"Rand Client","Servers AK","3 - Média","05/01/2015 09:13","3,0000000000","0","1"'
這些都是從CSV文件例如兩條線,你可以看到的第一個項目來報價外,還有不能分裂其他引號內的逗號。
代碼IVE tryied是這樣的:
$file = fopen("clientes/AMIL/Cliente_Prioridade.csv", "r");
while(! feof($file))
{
$csv_line[] = fgetcsv($file);
}
fclose($file);
foreach ($csv_line as $col) {
$line = $col[0];
$data[] = explode(',', $col[0]);
}
這有什麼結果的樣子。
array (size=278)
0 =>
array (size=7)
1 => string '"Acc Name"' (length=15)
2 => string '"Subject"' (length=9)
3 => string '"Priority"' (length=12)
4 => string '"Date"' (length=23)
5 => string '"Duration (Horas)"' (length=17)
6 => string '"Open"' (length=8)
7 => string '"Closed"' (length=9)
1 =>
array (size=9)
0 => string 'Andrew Deco' (length=11)
1 => string '"BANCO Example S/A"' (length=22)
2 => string '"Novo Processo - Pessoas Autorizadas a Abrir Chamado"' (length=62)
3 => string '"4 - Baixa"' (length=11)
4 => string '"05/01/2015 10:20"' (length=18)
5 => string '"6' (length=2)
6 => string '0000000000"' (length=11)
7 => string '"0"' (length=3)
8 => string '"1"' (length=3)
2 =>
array (size=9)
0 => string 'Not Atribuited' (length=14)
1 => string '"Agility Client"' (length=18)
2 => string '"Agility | Servers AD"' (length=25)
3 => string '"3 - Média"' (length=11)
4 => string '"05/01/2015 09:13"' (length=18)
5 => string '"3' (length=2)
6 => string '0000000000"' (length=11)
7 => string '"0"' (length=3)
8 => string '"1"' (length=3)
請清楚地表明:1)所使用的代碼,2)輸入給定的,3)預期結果,4)實際的結果。 – deceze 2015-02-07 13:18:39
@deceze預期的結果不是分割位置5和6,其中包含引用的逗號使其分裂。我在問題 – 2015-02-07 13:40:31