blob: ce44c811cb4948b96a9aacb17c4c177afedfd71a [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2class csv {
3 public static $fields = ["dni", "name", "category", "email", "companies"];
4
5 public static function csv2array($filename) {
6 $file = fopen($filename, "r");
7
8 $return = [];
9
10 $i = 0;
11 while (($line = fgetcsv($file, null, ";")) !== false) {
12 if ($i == 0) {
13 if (count($line) < count(self::$fields)) return false;
14
15 for ($j = 0; $j < count(self::$fields); $j++) {
16 if ($line[$j] !== self::$fields[$j]) return false;
17 }
18 } else {
19 $return[$i] = [];
20 foreach (self::$fields as $j => $field) {
21 $return[$i][$field] = trim($line[$j]);
22 }
23 }
24 $i++;
25 }
26
27 fclose($file);
28
29 return $return;
30 }
31}