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".

Yeah, thats the one i searched for, but couldn't get the answer

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

i am also confused how to get a specific row from a csv file, is anyone know how to do it ?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.