Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Created October 21, 2013 15:19
Show Gist options
  • Select an option

  • Save clouddueling/7085656 to your computer and use it in GitHub Desktop.

Select an option

Save clouddueling/7085656 to your computer and use it in GitHub Desktop.
csv splitting controller
<?php
class Test_Controller extends Base_Controller
{
public function get_index()
{
try {
$s = extend(array(
), sr());
$new_csv = array();
$rows = Parse::fromCSVFile("storage/work/sheet.csv");
foreach ($rows as $row) {
$name = explode(', ', $row[1]);
$row[] = isset($name[0]) ? $name[0] : '';
$row[] = isset($name[1]) ? $name[1] : '';
$new_csv[] = $row;
}
file_put_contents("storage/work/new.csv", Parse::toCSV($new_csv));
return json(array(
));
} catch(Exception $e) {
return Report::log($e->getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment