如何在PHP中跳过第一行并从csv文件中读取最多五行
你好,
我有以下代码,想要跳过csv文件的第一行即列头,并读取csv文件中的最多五行。
当前代码会跳过第一行但是显示所有记录。
我该如何实现这个功能?
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
set_time_limit(0);
define('CSV_PATH', '/var/www/Products_upload_12499/'); // specify CSV file path
$csv_file = CSV_PATH . "skipfirstrow.csv"; // Name of your CSV file
$csvfile = fopen($csv_file, 'r');
$counter = 1;
while ($data = fgetcsv($csvfile))
{
if($counter==1) {
$counter++;
continue;
} }
$days = trim($data[0]);
echo "==>> " . $days."\n";
if ($counter >= 6) {
exit();
}
}
?>