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 :

Dave
  • 28,833
  • 23
  • 113
  • 183
user1032289
  • 502
  • 5
  • 12
  • So you're getting the array, and you're asking how to display the value of that array? Seems like something that should be looked into for 30 seconds prior to asking here. Link to get you started: [http://www.tizag.com/phpT/arrays.php](http://www.tizag.com/phpT/arrays.php) – Dave Nov 07 '11 at 13:55
  • `get_headers` Inconsistency : http://stackoverflow.com/questions/12781795/get-headers-inconsistency – Baba Oct 08 '12 at 15:34

2 Answers2

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.

George Reith
  • 13,132
  • 18
  • 79
  • 148
0

Of just use

print_r(), var_dump() or var_export() 

to display result

pomaxa
  • 1,740
  • 16
  • 26