2017-02-12 77 views
0

我试图显示CSV文件数据,它位于gz文件中。PHP显示CSV文件,跳过第一行

我的代码是:

$file = file("compress.zlib://".$filePath); 

    foreach($file as $line){ 
    list($lid,$lname,$lrevenue,$ctr) = explode(",", $line); 

    print $lid ." | ". $lname ." | ". $lrevenue ." | ". $ctr . "\n"; 

    } 

此代码的工作,但我不知道如何跳过从它显示的第一行。

在此先感谢。

回答

1
$file = file("compress.zlib://".$filePath); 

unset($file[0]); 

foreach($file as $line){ 

    list($lid,$lname,$lrevenue,$ctr) = explode(",", $line); 
    print $lid ." | ". $lname ." | ". $lrevenue ." | ". $ctr . "\n";  
} 
+0

非常感谢你。有用。 :) – Geobo

+0

如果有帮助。请将其标记为正确的解决方案并进行投票,让其他人知道您的问题。不客气:)) – barbarity

+0

好的,谢谢你,我会的, – Geobo

1
$file = file("compress.zlib://".$filePath); 

$i=0; 
foreach($file as $line){ 

    if($i == 0) continue; 
    list($lid,$lname,$lrevenue,$ctr) = explode(",", $line); 
    print $lid ." | ". $lname ." | ". $lrevenue ." | ". $ctr . "\n"; 

    $i++; 
} 
+0

谢谢你的回复! – Geobo