对于PHP函数我们总能碰到不认识的,能掌握运用这些函数对我们来说很重要,他们能见证我们学习PHP的过程,所以我们要好好的善待他们。
get_headers函数
取得服务器响应一个 HTTP 请求所发送的所有标头。
array get_headers ( string $url [, int $format = 0 ] ) 比如,我们请求PHP乐知博客 http://tech.42xiu.com 看看返回是什么内容? Array ( [0] => HTTP/1.1 200 OK [1] => Server: nginx/1.2.4 [2] => Date: Tue, 15 Jan 2013 10:46:00 GMT [3] => Content-Type: text/html; charset=UTF-8 [4] => Connection: close [5] => X-Powered-By: PHP/5.3.8 [6] => Expires: Thu, 19 Nov 1981 08:52:00 GMT [7] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 [8] => Pragma: no-cache [9] => X-Pingback: http://tech.42xiu.com/action/xmlrpc [10] => Via: 10.67.15.24 [11] => Set-Cookie: saeut=123.150.158.150.1358246760544322; path=/; max-age=311040000 [12] => Set-Cookie: PHPSESSID=ee6260ade817060beac7405198ba514c; path=/; HttpOnly )
get_headers函数运用,比如在抓取图片时,可以先用此函数来判断图片url返回是否是200,来判断图片Url是否是有效地址,来决定要不要抓取这张图片。