回答編集履歴
1
追記
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
HTTPレスポンスヘッダを配列にしたいということでしょうか?
|
2
|
+
|
3
|
+
※コード追記しました
|
4
|
+
|
5
|
+
|
2
6
|
|
3
7
|
```ここに言語を入力
|
4
8
|
|
@@ -10,8 +14,66 @@
|
|
10
14
|
|
11
15
|
|
12
16
|
|
13
|
-
$header = substr($output, 0, $info["header_size"]);
|
17
|
+
$header = get_headers_from_curl_response(substr($output, 0, $info["header_size"]));
|
14
18
|
|
15
19
|
$body = substr($output, $info["header_size"]);
|
16
20
|
|
21
|
+
|
22
|
+
|
23
|
+
static function get_headers_from_curl_response($headerContent)
|
24
|
+
|
25
|
+
{
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
$headers = array();
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
$arrRequests = explode("\r\n\r\n", $headerContent);
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// Loop of response headers. The "count() -1" is to
|
38
|
+
|
39
|
+
//avoid an empty row for the extra line break before the body of the response.
|
40
|
+
|
41
|
+
for ($index = 0; $index < count($arrRequests) -1; $index++) {
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
foreach (explode("\r\n", $arrRequests[$index]) as $i => $line)
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
if ($i === 0)
|
50
|
+
|
51
|
+
$headers[$index]['http_code'] = $line;
|
52
|
+
|
53
|
+
else
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
list ($key, $value) = explode(': ', $line);
|
58
|
+
|
59
|
+
$headers[$index][$key] = $value;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
return $headers;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
17
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|