php get_headers 与get_meta_tags函数实例

get_headers是获取http头信息,get_meta_tags是获取网页的description,abstract,keywords等信息.

  1. */
  2. $url='http://www.phpfensi.com'; //定义url
  3. print_r(get_headers($url)); //无格式获取
  4. print_r(get_headers($url,1)); //带上格式获取
  5. /*
  6. array
  7. (
  8. [0] => http/1.1 200 ok
  9. [1] => connection: close
  10. [2] => date: sat, 11 dec 2010 05:43:46 gmt
  11. [3] => content-length: 69617
  12. [4] => content-type: text/html
  13. [5] => content-location: http://www.phpfensi.com/index.html
  14. [6] => last-modified: sat, 11 dec 2010 05:19:51 gmt
  15. [7] => accept-ranges: bytes
  16. [8] => etag: "e8be4b9f398cb1:6c66"
  17. [9] => server: microsoft-iis/6.0
  18. [10] => x-powered-by: asp.net
  19. )
  20. array
  21. (
  22. [0] => http/1.1 200 ok
  23. [connection] => close
  24. [date] => sat, 11 dec 2010 05:43:47 gmt
  25. [content-length] => 69617
  26. [content-type] => text/html
  27. [content-location] => http://www.phpfensi.com/index.html
  28. [last-modified] => sat, 11 dec 2010 05:19:51 gmt
  29. [accept-ranges] => bytes
  30. [etag] => "e8be4b9f398cb1:6c66"
  31. [server] => microsoft-iis/6.0
  32. [x-powered-by] => asp.net
  33. )
  34. get_meta_tags($url);
  35. 获取指定网页的description,abstract,keywords等信息
  36. */
  37. $tags=get_meta_tags('http://www.phpfensi.com/'); //提取meta标签
  38. print_r($tags) //输出数组全部内容
  39. /*
  40. array
  41. (
  42. [description] => 网页制作教程网提供专业网页设计教程与网页制作教程包括有photoshop教程,flash,html,css教程,dreamweaver,fireworks,asp,php教程,jsp教程,asp.net,网站建设,网站开发,网页特效,平面设计,个人网站,网页素材
  43. [abstract] => 提供最新的网页制作教程、网页设计教程、网页特效,为个人网站提供网页素材模板和网页视频学习。
  44. [keywords] => 网页设计教程,网页制作教程,网页学习,photoshop,flash,html,css,dreamweaver,fireworks,asp,php,jsp,asp.net,网页特效,平面设计,网页素材
  45. )

注意:使用该函数需要把 php.ini里面的allow_url_fopen = on,才能使用.