php get_headers location

fish man picture fish man · Oct 29, 2011 · Viewed 7.9k times · Source

how to use php get_headers only get location part?

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

This return:

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

Then I use

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

error: Parse error: syntax error, unexpected '[' in this echo line

Answer

Christian P picture Christian P · Oct 29, 2011
$headers = get_headers('http://www.google.com',1);
echo $headers["Location"];