php教程

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

php教程 51源码 2022-11-16 人阅读

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

<?php
header("content-type:text/html; charset=utf8");
$arr = file("http://www.51yma.cn");
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函数。


上一篇:readFile()函数判断文件是否读取完成 下一篇:返回列表 栏目分类

帝国CMS教程

织梦cms教程

discuz教程

ecshop教程

phpcms教程

wordpress教程

苹果cms教程

php教程

数据库教程

微信小程序教程

python教程

css教程

js教程

视频教程

电子书

热门推荐
版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/jiaocheng/php/592.html
文章来源:
标签