1

I was used to get_headers() function

`$`url = 'http://stackoverflow.com';
$s=get_headers(`$`url, 1);
print_r(`$`s);

then i got output like

Array ( [0] => HTTP/1.1 200 OK [Cache-Control] => public, max-age=27 [Content-Type] => text/html; charset=utf-8 [Expires] => Mon, 07 Nov 2011 13:44:38 GMT [Last-Modified] => Mon, 07 Nov 2011 13:43:38 GMT [Vary] => * [Date] => Mon, 07 Nov 2011 13:44:10 GMT [Connection] => close [Content-Length] => 195251 ) 

How can display like

Cache-Control :

Content-Type :

Expires :

Last-Modified :

Connection :

Content-Length :

2

2 Answers 2

3

get_headers() returns an array. If you set the second optional paramater to 1 then it will return an array with intuitive keys.

E.g. getheaders($url, 1)

You can print them seperately like so:

$url = 'http://stackoverflow.com';
$s = get_headers($url, 1);

print("Cache-Control: ".$s[Cache-Control]."\n");
print("Content-Type: ".$s[Content-Type]."\n");
print("Expires: ".$s[Expires]."\n");
print("Last-Modified: ".$s[Last-Modified]."\n");

For a full definition see the PHP manual.

Sign up to request clarification or add additional context in comments.

Comments

0

Of just use

print_r(), var_dump() or var_export() 

to display result

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.