我正在尝试使用fgets
从csv文件中读取数据。但是,我希望通过前两个顶行。
默认情况下,fgets
仅传递第一行。如何通过前两个顶行来调整它?
$myfile = "/home/dibon/AML_Data/test.csv";
$myfile = fopen("$myfile", "r") or die("Unable to open file!");
fgets($myfile); //First fgets to read over header line.
while($line=fgets($myfile)){
//Explode your line by space delimeter
$words=explode("|",$line);
DB::table('transaction_incremental')->insert(
['ReceiptNumber' => "$words[0]", 'InitiatingMSISDN' => "$words[2]"]
);
}
答案 0 :(得分:0)
fgetcsv($handle); // get line 0 and move to next
fgetcsv($handle); // get line 1 and move to next
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
....
}