質問編集履歴
2
整理
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,7 +58,7 @@
|
|
58
58
|
|
59
59
|
$jsonb = json_decode($one->context);
|
60
60
|
|
61
|
-
|
61
|
+
|
62
62
|
|
63
63
|
fputcsv($stream, [
|
64
64
|
|
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,115 @@
|
|
7
7
|
解決方法はありますか?
|
8
8
|
|
9
9
|
よろしくお願いいたします。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
現在のコード
|
16
|
+
|
17
|
+
```php
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
$all = ......DBからデータを取得する
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
$stream = fopen('php://temp', 'w');
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
fputcsv($stream,[
|
30
|
+
|
31
|
+
'タイトル1'
|
32
|
+
|
33
|
+
,'タイトル2'
|
34
|
+
|
35
|
+
,'タイトル3'
|
36
|
+
|
37
|
+
,'タイトル4'
|
38
|
+
|
39
|
+
,'タイトル5'
|
40
|
+
|
41
|
+
,'タイトル6'
|
42
|
+
|
43
|
+
,'タイトル7'
|
44
|
+
|
45
|
+
,'タイトル8'
|
46
|
+
|
47
|
+
]
|
48
|
+
|
49
|
+
);
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
foreach ($all as $one) {
|
54
|
+
|
55
|
+
$jsonb = "";
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
$jsonb = json_decode($one->context);
|
60
|
+
|
61
|
+
// var_dump($jsonb->switch);exit;
|
62
|
+
|
63
|
+
fputcsv($stream, [
|
64
|
+
|
65
|
+
$one->data,//$one->dataはjsonの場合、「{\"text\": \"こんにちは\"\」と「\"type\": \"text\"}""」になる
|
66
|
+
|
67
|
+
$one->data,
|
68
|
+
|
69
|
+
$one->data,
|
70
|
+
|
71
|
+
$jsonb->data,
|
72
|
+
|
73
|
+
$jsonb->data,
|
74
|
+
|
75
|
+
$one->data,
|
76
|
+
|
77
|
+
$one->data,
|
78
|
+
|
79
|
+
$one->data,
|
80
|
+
|
81
|
+
],
|
82
|
+
|
83
|
+
',',
|
84
|
+
|
85
|
+
'"',
|
86
|
+
|
87
|
+
'"'
|
88
|
+
|
89
|
+
);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
rewind($stream);
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
$csv = str_replace(PHP_EOL, "\r\n", stream_get_contents($stream));
|
98
|
+
|
99
|
+
$csv = mb_convert_encoding($csv, 'SJIS-win', 'UTF-8');
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
$filename = date("Ymd_Hi",time()).'.csv';
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
$headers = array(
|
108
|
+
|
109
|
+
'Content-Type' => 'text/csv',
|
110
|
+
|
111
|
+
'Content-Disposition' => 'attachment; filename*=UTF-8\'\''.rawurlencode($filename),
|
112
|
+
|
113
|
+
);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
return response($csv,200,$headers);
|
120
|
+
|
121
|
+
```
|