Posted By

bionickid on 11/25/10


Tagged

array csv


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vehler
mikael12


csv to array


 / Published in: PHP
 

simple one to parse csv files from excel

  1. function csv2array($file) {
  2. $file = file('fragebogenDaten.csv');
  3. $data = array();
  4. foreach ($file as $lineNumber => $line) {
  5. if($lineNumber == 0) {
  6. $keys = explode(';', $line);
  7. foreach($keys as $k=>$v)
  8. $keys[$k] = trim($v);
  9. }
  10. else {
  11. $values = explode(';', $line, sizeof($keys));
  12. $data[$lineNumber-1] = array_combine($keys, $values);
  13. }
  14. }
  15. return $data;
  16. }

Report this snippet  

You need to login to post a comment.