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

From: Date: Mon, 30 Apr 2007 04:06:52 +0000
Subject: Delete first line of a csv file if it is the headers
Groups: php.general 
Request: Send a blank email to php-general+get-254128@lists.php.net to get a copy of this message
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'; }

« previous php.general (#254128) next »