php教程

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

我的站长站 2022-11-15 人阅读

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

<?php
header("content-type:text/html; charset=utf8");
$arr = file("http://www.wdzzz.com");
if($arr){
    foreach($arr as $a){
        if(strchr($a,"<title>")){
            $a = str_ireplace("<title>","",$a);
            $a = str_ireplace("</title>","",$a);
            echo $a;//标题
            break;
        }
    }
}
$meta_array = get_meta_tags('http://www.dedecmsok.com');
echo $meta_array["keywords"];//关键词
echo $meta_array["description"];//描述
?>

如果使用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函数。


相关推荐
  • php获取
  • php获取文件后缀扩展名三种方法分享

    本文中,我们介绍三种php获取文件扩展名的方法方法一:使用PHP pathinfo()获取文件扩展名方法二:使用PHP SplFileInfo类获取文件后缀方法三:使用PHP substr()和strrchr()函数获取文件扩展名pathinfo()获取方法pathinfo() 函数以数组的形式返回关于文件路径...

    php教程 41 1年前
  • filesize()函数获取文件大小的方法

    filesize()函数使用方法filesize()函数可以直接获取文件的字节数,代码如下:echo filesize(“upload.php”);通过浏览器访问,我们可以看到,直接输出获取的文件大小的字节。常用方法封装我们都知道文件大小,除了用字节数表示更常见的是用KB、MB、GB、TB这些...

    php教程 32 1年前
  • php获取年月周时间戳代码

    php获取时区date_default_timezone_set("Asia/Shanghai"); date_default_timezone_set(&#39;PRC&#39;);//这两种方法效果相同时间戳转日期,可以用date(‘Y-m-s h:i:s’, 具体时间戳来实现)日期转换时间戳,用strtotime("date()").php获取时间戳//获取今...

    php教程 11 1年前
最新更新