开发者

How can I account for headers that don't follow proper capitalization?

开发者 https://www.devze.com 2023-02-12 10:02 出处:网络
Updated Question: When using get_headers() with the format option to use named array keys (rather than numbered keys), how can I account for situations like the server using Content-type rather than

Updated Question:

When using get_headers() with the format option to use named array keys (rather than numbered keys), how can I account for situations like the server using Content-type rather than Content-Type?


Original Question: PHP problem getting header of a file that has a colon in url

Hi, I am having trouble retrieving header information of a remote url which has a colon in it. I have tried us开发者_运维知识库ing urldecode and it decodes %3A into :, however it does not solve the problem. What to do?

This url: http://string-theory.wdfiles.com/local--files/char%3Ajezebel/evangeline-lilly-picture-4a.jpg


Updated Answer:

If you can't guarantee that the server uses correct capitalization, you can use array_change_key_case to change the named keys.

<?php
    $original = array('Content-type'=>'text/html');
    echo $original['Content-Type']; // Notice: Undefined index

    $fixed = array_change_key_case($original, CASE_LOWER);
    echo $fixed['content-type']; // prints 'text/html'
?>


Old Answer:

You're going to have to expand on your question, because this works just perfectly:

PHP:

<?php
    $url = 'http://www.mysite.com/dev/blah.php?blah=1:2:3';
    print_r(get_headers($url));
?>

Output:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Tue, 22 Feb 2011 18:28:20 GMT
    [2] => Server: Apache
    [3] => Connection: close
    [4] => Content-Type: text/html
)

Output 2: (using URL given by OP)

Array
(
    [0] => HTTP/1.0 200 OK
    [1] => Etag: "8b48b69ed24101b9a235e0168874c720"
    [2] => Content-type: image/jpeg; charset=utf-8
    [3] => Content-Length: 482111
    [4] => Connection: close
    [5] => Date: Wed, 23 Feb 2011 19:50:42 GMT
    [6] => Server: lighttpd/wikidot
)
0

精彩评论

暂无评论...
验证码 换一张
取 消