PHP获取网站标题+描述+关键字代码,无需第三方接口

 2684

原生PH获取标题(title)、描述(description)、关键字(keywords)代码,无需第三方API接口。


PHP获取网站标题+描述+关键字代码,无需第三方接口


  1. <?php
  2. header("content-type:text/html; charset=utf8");
  3. $arr = file("http://www.zztuku.com");
  4. if($arr){
  5.     foreach($arr as $a){
  6.         if(strchr($a,"<title>")){
  7.             $a = str_ireplace("<title>","",$a);
  8.             $a = str_ireplace("</title>","",$a);
  9.             echo $a;//标题
  10.             break;
  11.         }
  12.     }
  13. }
  14. $meta_array = get_meta_tags('http://www.zztuku.com');
  15. echo $meta_array["keywords"];//关键词
  16. echo $meta_array["description"];//描述
  17. ?>

如果使用PHP.ini默认配置,用file_get_contents读取https的链接,就会如下错误:

Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?


解决方案:

1、php.ini中把extension=php_openssl.dll前面的;删掉,重启服务就可以了。

2、Linux下的PHP,安装openssl模块,安装好了以后就可以访问了。

3、如果不能修改配置,就只换curl函数来替代file_get_contents函数。


TAG标签:
本文网址:https://www.zztuku.com/detail-13354.html
站长图库 - PHP获取网站标题+描述+关键字代码,无需第三方接口
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐