Delete first line of a csv file if it is the headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



     The below script will parse a csv file to a database I need to remove
the first line because it is the header files and I don't need them. How can
I test for that and remove them.
 
 $file = fopen($_POST['copy'], 'r') or $message .= "Could not open" .
$_POST[copy] . "for reading.<BR>\n";
                while (!feof($file)){
                    # We could easily be importing 10,000 records.  Give us
some time here, okay?
                    set_time_limit(30);
                    $fields = fgetcsv($file, 1000000);
   
                    if ($fields && count($fields)){
                        $recordcount++;
 
                        # Wipe out every possible field, in case they have
some missing:
                        reset($possiblefields);
                        while (list(,$fieldname) = each($possiblefields)){
                            $$fieldname = '';
                        }
 
                        reset($_POST['fieldorder']);
                        $fieldcount = 0;
                        $notes = '';
                        while (list(,$field) = each($fields)){
                            $fieldname =
$_POST['fieldorder'][$fieldcount++];
                            if ($fieldname == 'notes'){
                                $notes .= addslashes("$field\n");
                            }
                            elseif ($fieldname == '-- ignore --'){
                                # ignore it
                            }
                            else{
                                # Note that file data is not Magic-Quoted:
                                $$fieldname = addslashes($field);
                            }
                        }
                          require 'importinsert.php';
                    }

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux