回答編集履歴
2
chousei
test
CHANGED
@@ -9,8 +9,6 @@
|
|
9
9
|
<?PHP
|
10
10
|
|
11
11
|
$fp=fopen("myfile.txt","r");
|
12
|
-
|
13
|
-
$c=0;
|
14
12
|
|
15
13
|
while(($data=fgetcsv($fp,1024))!==false){
|
16
14
|
|
@@ -34,6 +32,34 @@
|
|
34
32
|
|
35
33
|
```
|
36
34
|
|
35
|
+
冗長に書くとこんな感じ
|
36
|
+
|
37
|
+
```PHP
|
38
|
+
|
39
|
+
$fp=fopen("myfile.txt","r");
|
40
|
+
|
41
|
+
while(($data=fgetcsv($fp,1024))!==false){
|
42
|
+
|
43
|
+
$tmp=&$datas[];
|
44
|
+
|
45
|
+
foreach($data as $x){
|
46
|
+
|
47
|
+
$y=explode("=",$x);
|
48
|
+
|
49
|
+
$tmp[trim($y[0])]=trim($y[1]);
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
unset($tmp);
|
56
|
+
|
57
|
+
fclose($fp);
|
58
|
+
|
59
|
+
print json_encode($datas,JSON_UNESCAPED_UNICODE);
|
60
|
+
|
61
|
+
```
|
62
|
+
|
37
63
|
- 結果
|
38
64
|
|
39
65
|
```json
|
1
chousei
test
CHANGED
@@ -33,3 +33,11 @@
|
|
33
33
|
print json_encode($datas,JSON_UNESCAPED_UNICODE);
|
34
34
|
|
35
35
|
```
|
36
|
+
|
37
|
+
- 結果
|
38
|
+
|
39
|
+
```json
|
40
|
+
|
41
|
+
[{"名前":"ハンバーグ","分類":"洋食","主成分":"タンパク質"},{"名前":"寿司","分類":"和食","主成分":"炭水化物"},{"名前":"牛乳","分類":"飲み物","主成分":"カルシウム"}]
|
42
|
+
|
43
|
+
```
|