Skip to content

Instantly share code, notes, and snippets.

@florentdestremau
Created February 17, 2017 13:58
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 florentdestremau/8d191f722b9c179c6d869c5d6033b9d2 to your computer and use it in GitHub Desktop.
Save florentdestremau/8d191f722b9c179c6d869c5d6033b9d2 to your computer and use it in GitHub Desktop.
Simple symfony command to read a csv file in project root
<?php
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('file');
$fileName = $this->getContainer()->get('kernel')->getRootDir() . DIRECTORY_SEPARATOR . "../$file";
$output->writeln($fileName);
if (($handle = fopen($fileName, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// your csv line $data is an array, do whatever you want
}
fclose($handle);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment