【问题标题】:php get_headers locationphp get_headers 位置
【发布时间】:2011-10-29 07:54:39
【问题描述】:

如何使用 php get_headers 只获取位置部分?

var_dump(get_headers('http://www.google.com',1));

这个回报:

array(12) { [0]=> string(18) "HTTP/1.0 302 Found" ["Location"]=> string(21) "http://www.google.it/" ... }

然后我用

echo (get_headers('http://www.google.com',1)["Location"];

错误:Parse error: syntax error, unexpected '[' 在此 echo 行中

【问题讨论】:

    标签: php get-headers


    【解决方案1】:
    $headers = get_headers('http://www.google.com',1);
    echo $headers["Location"];
    

    【讨论】:

    • 谢谢,这没有错误。顺便说一句,你认为$headers 更快还是curl - curl_getinfo($ch, CURLINFO_HTTP_CODE); 更快
    • @fishman 没有尝试测量它,但在php.net/manual/en/function.get-headers.php 用户 damolp 中说 cURL 是获取标头的最快方法。
    • @fishman 你因为提出无意义的问题而得到-1。 curl 和 get 标头都必须处理网络延迟,并且它们都不能加快速度。
    • 对我来说只有小写字母有效,即 echo $headers["location"];
    猜你喜欢
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 2019-02-24
    • 2012-01-14
    • 2010-12-05
    相关资源
    最近更新 更多