Anyone know how to read the second line from a csv file using PHP? I need the read the second line from the csv file and import into mysql

Is there mentioned how to read second row onwards or any particular row onwards from csv file? I try look at that wrbsite but couldn't find it.

Is there mentioned how to read second row onwards or any particular row onwards from csv file? I try look at that wrbsite but couldn't find it.

Right in the middle of the table of contents there is a link to the section "Working with CSV".

This code opens and reads a line into $line until there are no more lines:

<?php
  $fp = fopen('file.csv', 'r');
  while (!feof($fp)) {
    $line = fgetcsv($fp, 4096);
    echo $line; // do whatever you need here
  }
  fclose($fp);
?>

file_get() can be used as well, to load each line into an array, if you prefer to work with it like that.

Alright, i got you now. meaning i can do some skipping code to replace
echo $line; // do whatever you need here

with some code that read the string is not equal to the column name in the csv file and proceed to insert.

Thanks for your help. Really appreciated

Did you read any of the posts above? Did you understand them? If not, what didn't you understand? You need to learn how to ask questions.

This article has been dead for over six months. Start a new discussion instead.