php get_headers location

8.2k Views Asked by At

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

1

There are 1 best solutions below

4
On BEST ANSWER
$headers = get_headers('http://www.google.com',1);
echo $headers["Location"];