Created
February 17, 2017 13:58
-
-
Save florentdestremau/8d191f722b9c179c6d869c5d6033b9d2 to your computer and use it in GitHub Desktop.
Simple symfony command to read a csv file in project root
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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