【发布时间】:2013-02-19 09:23:04
【问题描述】:
我通过使用 cURL 得到以下字符串。代码可以在this comment找到。
HTTP/1.1 200 OK ID=347 Date: Tue, 19 Feb 2013 09:15:25 GMT Server:
Apache/2.2.22 (Ubuntu) Content-length: 0 Vary: Accept-Encoding
Content-Type: text/plain; charset=ISO-8859-1
现在我想要字符串中的 ID,为此我使用了 explode 从空间中创建一个数组,如下所示:
$getIdElem = explode(' ',$output);
echo '<pre>';print_r($getIdElem);
但我得到带有 ID 字符串的 Date: ,而它前面有空格。打印数组的输出是:
Array
(
[0] => HTTP/1.1
[1] => 200
[2] => OK
[3] => ID=347
Date:
[4] => Tue,
[5] => 19
[6] => Feb
[7] => 2013
[8] => 09:15:25
[9] => GMT
Server:
[10] => Apache/2.2.22
[11] => (Ubuntu)
Content-length:
[12] => 0
Vary:
[13] => Accept-Encoding
Content-Type:
[14] => text/plain;
[15] => charset=ISO-8859-1
)
我不明白为什么它不包含该空间的爆炸功能。谁能帮我解决这个问题?
【问题讨论】:
-
中间不是空格而是换行符。
-
是什么让您认为所有这些 HTTP 标头都在一行中?
-
@ÁlvaroG.Vicario 因为它有来自服务器的文本/纯文本响应
-
@str 谢谢我是 PHP 新手,所以只需要问一下我们如何用新行来扩展它?
-
explode("\n", $output)