how to start reading a file in line number 5?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kid
    New Member
    • Jul 2007
    • 13

    how to start reading a file in line number 5?

    i have a file(CSV) and the contents are:

    Data A,,,,DATA B,,
    ,,7/12/2007,,,,7/12/2007
    ,,1:00,,,,1:00
    NAME,REGION ID,Prices,,NAME ,REGION ID,Prices
    (RESOURCE ID),,(QUANTITY) ,,(RESOURCE ID),,(QUANTITY)

    AORT,6,"4,153.4 0",,TRIBU,3,"4, 153.40"
    BIGTH,2,"4,067. 08",,YLUJ,1,"4, 056.45"
    STRT,9,"4,067.0 8",,TSLO,8,"4,0 56.45"

    Situation:
    i want to store all of this strings to MySQL except for the bold ones.
    how can i place my pointer in line number 5?

    badly needed please help thanks.
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use fgetcsv() to read your csv file. It returns a signle line, in while loop you can check on which line number you are e.g.
    [PHP]$row = 1;
    $handle = fopen("test.csv ", "r");
    while (($data = fgetcsv($handle , 1000, ",")) !== false)
    {
    if($row<5) continue;
    // do your stuff here

    $row++;
    }
    fclose($handle) ;[/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      MySQL's LOAD DATA INFILE command has an option to IGNORE # LINES, if you decide to go that route.

      Comment

      Working...