我有一件有趣的工作要完成如何使用fgetcsv從CSV中獲取特定列?
我有很多電子表格,我已經轉換爲CSV - 這些電子表格最初是作爲具有一定數量的列的模板。
不幸的是,隨着時間的推移,人們添加了列並將其刪除。
有沒有一種方法,我可以適應下面的代碼從每個CSV
foreach($fileinfos as $pathname => $fileinfo) {
if (!$fileinfo->isFile()) continue;
if(substr($pathname,-3) == 'csv'){
$file = fopen($pathname, "r");
while ($line = fgetcsv($file,0,'^','¬')){
echo substr($pathname,56) .' '.$numcols.'<br>';
}
fclose($file);
}
}
UPDATE選擇特定的列名:
這是我接受的列
Array
(
[0] => Date Raised
[1] => QA phase
[2] => Item ID
[3] => Screen Number
[4] => Reason
[5] => Matches originals?
[6] => Issue/Comments
[7] => Raise with Client?
[8] => Raised By
[9] => Status
[10] => TP/AS Status Initials
[11] => TP/AS Status date
[12] => TP/AS Status Comment
[13] => Retested by
[14] => Retested date
[15] => Retested Comment
)
這裏的數組是我的一系列禮品
Array
(
[0] => Date Raised
[1] => QA phase
[2] => Item ID
[3] => Screen Number
[4] => exam
[5] => Reason
[6] => Matches originals?
[7] => Issue/Comments
[8] => Raise with Client?
[9] => Raised By
[10] => Status
[11] => TP/AS Status Initials
[12] => TP/AS Status date
[13] => TP/AS Status Comment
[14] => dd Comments
[15] => PM Comments
[16] => Retested by
[17] => Retested date
[18] => Retested Comment
)
數組結合dosnt工作。
是有第一條線確定th e列名?您可以閱讀第一行並記住列名,以在後面的所有行上創建一個數組,列名將用作此數組中的鍵 –
第一行包含列名稱 - 那麼您是說解析第一行然後從那裏建立一個數組,並使用鍵跳過某些列? – Rob