Skip to content

Instantly share code, notes, and snippets.

@dpmckenzie
Created September 24, 2012 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpmckenzie/3774129 to your computer and use it in GitHub Desktop.
Save dpmckenzie/3774129 to your computer and use it in GitHub Desktop.
My not-quite-functioning CSV-modifying PHP file--not functioning even after class help. If anyone has ideas, do tell. I meanwhile have learned a faster way to do this. :)
<?php
ini_set("auto_detect_line_endings", true);
$fileName = 'cases.csv';
// set function for opening file
$file = fopen($fileName, "r+") or die("can't open file");
// recognize file as csv, get it to loop
while(($data = fgetcsv($file, 1000, ',')) !== FALSE) {
// set the second column to old date
$old_date = $data[1];
// switch the order
$new_date = explode('/', $old_date);
$date = $new_date[2].'-'.$new_date[0].'-'.$new_date[1];
// set the second column to new date
$data[1] = $date;
fputcsv($file, $data);
}
// close csv file
fclose($file);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment