title: How to skip first row and read upto five rows from csv in PHP
body: <p>How to skip first row and read upto five rows from csv in PHP</p>
  
  <p>Hello,</p>
  
  <p>I have following code in which I want to skip first row in csv that is headers of columns and read upto five rows of csv file.</p>
  
  <p>Current code skip first row but display all records. </p>
  
  <p>How can I achieve this ?</p>
  
  <pre><code>&lt;?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 "==&gt;&gt; " . $days."\n";
          if ($counter &gt;= 6) {
          exit();
      }
  
  }
  
  ?&gt;
  </code></pre>