I am trying to read a couple column values of a spreadsheet (13 columns X 4000 rows) saved as a csv file. I believe my code is correctly looking to process the csv file by rows. When I run the code the parser appears to be looking past the data as it errors looking for key 14 and above. I want to read the filename to append/rename and then put the last edit date into a new csv or replace. I found some issues in the csv file as it was adding extra data when finding characters like commas and double quotes but I removed them.
$fname="index_csv.csv";
$fnamenew="indexnew.csv";
$xhandle= fopen ($fnamenew, "a");
if (($handle=fopen ($fname, "r")) !==FALSE){
while(($line = fgetcsv($handle)) !== FALSE) {
list($totstring, $totlen, $period, $http, $lenanna, $lentitle, $post, $title, $fnamelen, $old, $oldlessext, $bat, $fcdate) = $line;
if(file_exists($old)){
$cfiledate= date('y-m-d',filectime($old));
$new=$post . "_". $old; // this adds the post number to the beginning of the file name.
echo "Now processing: " . $new . "<br>";
rename ($old, $new);
$newline = array($totstring, $totlen, $period, $http , $lenanna , $lentitle, $post, $title, $fnamelen, $old, $oldlessex, $bat, $cfiledate);
fputcsv ($fnamenew, $newline);
unlink($old);
}
}
}
fclose($handle);
fclose($xhandle);
?>