我无法获得我写过的新代码来跳过第一行(标题),因为我以前使用的代码(参见下文)。如何在我的while循环中使用fgetcsv跳过标题行?
我没有收到任何错误,但只是无法让它省略第一行。
$file = fopen($uploadcsv,"r");
$column_headers = array();
$row_count = 0;
while(!feof($file)) {
if ($row_count==0){
$column_headers = $file;
} else {
print_r(fgetcsv($file));
}
++$row_count;
}
fclose($file);
下面是跳过标题的旧来源,供参考和比较。
$handle = fopen($uploadcsv, 'r');
$column_headers = array();
$row_count = 0;
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) {
if ($row_count==0){
$column_headers = $data;
} else {
print_r($data);
}
++$row_count;
}
fclose($handle);
请解释一下?所以不要使用$ row_count == 0?我将需要将其分配给数组$ – acctman 2010-12-10 15:09:45
您决定让我们惊讶的是什么“$ data”? – 2010-12-10 15:12:24
哦,我很抱歉,如果你看看编码顶部(旧编码),我使用数据$数据 – acctman 2010-12-10 16:03:15