·设为首页收藏本站📧邮箱修改🎁免费下载专区💎积分✅卡密📒收藏夹👽聊天室
返回列表 发布新帖

php的问题,研究了很久没有搞好。

138 6
发表于 2023-8-6 23:21:04 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. <?php/** 获取META信息 */function get_sitemeta($url) {         $data = file_get_contents($url);              $meta = array();     if (!empty($data)) {          #Title          preg_match('/<TITLE>([\w\W]*?)<\/TITLE>/si', $data, $matches);          if (!empty($matches[1])) {               $meta['title'] = $matches[1];          }                   #Keywords          preg_match('/<META\s+name="keywords"\s+content="([\w\W]*?)"/si', $data, $matches);                   if (empty($matches[1])) {               preg_match("/<META\s+name='keywords'\s+content='([\w\W]*?)'/si", $data, $matches);                        }          if (empty($matches[1])) {               preg_match('/<META\s+content="([\w\W]*?)"\s+name="keywords"/si', $data, $matches);                        }          if (empty($matches[1])) {               preg_match('/<META\s+http-equiv="keywords"\s+content="([\w\W]*?)"/si', $data, $matches);                        }          if (!empty($matches[1])) {               $meta['keywords'] = $matches[1];          }                   #Description          preg_match('/<META\s+name="description"\s+content="([\w\W]*?)"/si', $data, $matches);                   if (empty($matches[1])) {               preg_match("/<META\s+name='description'\s+content='([\w\W]*?)'/si", $data, $matches);                        }          if (empty($matches[1])) {               preg_match('/<META\s+content="([\w\W]*?)"\s+name="description"/si', $data, $matches);                                  }          if (empty($matches[1])) {               preg_match('/<META\s+http-equiv="description"\s+content="([\w\W]*?)"/si', $data, $matches);                        }          if (!empty($matches[1])) {               $meta['description'] = $matches[1];          }     }      return $meta;}?>                        <?php$stie =get_meta_tags('http://www.'.$_GET['url']);$title = $stie['title'];$keywords = $stie['keywords'];$description = $stie['description'];echo "<b>网站标题:</b> $title<br>";echo "<b>网站关键字:</b> $keywords<br>";echo "<b>网站描述:</b> $description<br>";?>        
复制代码
为什么 网站标题 一直没有获取到。。。这样的问题,研究了很久没有搞好。有没有大神帮忙改一改。
我要说一句 收起回复
创宇盾启航版免费网站防御网站加速服务

评论6

TyCodingLv.8 发表于 2023-8-6 23:21:19 | 查看全部
占个坑,蹲一下!需要这样的API
我要说一句 收起回复
IT618发布Lv.8 发表于 2023-8-6 23:22:12 | 查看全部
标签大小写
我要说一句 收起回复
婷姐Lv.8 发表于 2023-8-6 23:22:46 | 查看全部
占个坑,蹲一下!需要这样的API
我要说一句 收起回复
IT618发布Lv.8 发表于 2023-8-6 23:23:11 | 查看全部
header( "content-type:text/html; charset=xxx" );//编码问题
get_meta_tags("http://www.4414.cn/");//PHP内置函数


//Xpath 方式
$res = file_get_contents($url);
$dom = new DOMDocument();
$dom->loadHTML($res);
$dom->normalize();
$xpath = new DOMXPath($dom);
$data = $xpath->query('/html/head/title');//取title meta等
var_dump($data->item(0)->nodeValue);
我要说一句 收起回复
TyCodingLv.8 发表于 2023-8-6 23:24:11 | 查看全部
为什么一定是大写的meat呢?大部分都是小写。不区分大小写会不会好点?
我要说一句 收起回复
TyCodingLv.8 发表于 2023-8-6 23:25:05 | 查看全部
占个坑,蹲一下!需要这样的API
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

图文热点
创宇盾启航版免费网站防御网站加速服务
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.15.29.248,GMT+8, 2024-10-18 18:19 , Processed in 0.266733 second(s), 110 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2024 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表