File tree 1 file changed +12
-4
lines changed
1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
// Created by Yehuda Eisenberg
4
4
5
- function parseCsv ($ filename , $ header = true ){
5
+ function parseCsv ($ filename , $ title = true ){
6
6
$ dataText = file_get_contents ($ filename );
7
7
$ dataArr = explode ("\n" , $ dataText );
8
8
9
- if ($ header ){
9
+ if ($ title ){
10
10
$ names = explode (", " , $ dataArr [0 ]);
11
11
unset($ dataArr [0 ]);
12
12
}
@@ -16,8 +16,16 @@ function parseCsv($filename, $header = true){
16
16
$ data = explode (", " , $ data );
17
17
$ tmp = array ();
18
18
foreach ($ data as $ i => $ dat ){
19
- if ($ header )
20
- $ tmp [trim ($ names [$ i ])] = trim ($ dat );
19
+ if ($ title ){
20
+ if (isset ($ tmp [trim ($ names [$ i ])])){
21
+ if (is_string ($ tmp [trim ($ names [$ i ])]))
22
+ $ tmp [trim ($ names [$ i ])] = array ($ tmp [trim ($ names [$ i ])], trim ($ dat ));
23
+ else
24
+ $ tmp [trim ($ names [$ i ])][] = trim ($ dat );
25
+ }
26
+ else
27
+ $ tmp [trim ($ names [$ i ])] = trim ($ dat );
28
+ }
21
29
else
22
30
$ tmp [$ i ] = trim ($ dat );
23
31
}
You can’t perform that action at this time.
0 commit comments