本api是本地获取的,可用于域名一键获取标题、关键词、描述等操作,做导航的小伙伴可以看看,使用格式api地址+?url=查询域名~
代码如下:
- <?php
- if ($_GET['url']) {
- $site='http://';
- $url=trim($site.$_GET['url']);
- $info=file_get_contents($url);
- header('Content-type:text/json');
- function _charset($url){
- $text = file_get_contents($url);
- $mode = '/charset=(.*)\"/iU';
- preg_match($mode,$text,$result);
- return $result[1];
- }
- $charset = _charset($url);
- function _title($url,$charset){
- $text = file_get_contents($url);
- if ($charset == 'gb2312'){
- $text = iconv('gb2312','utf-8',$text);
- }
- $mode = '/<title>(.*)<\/title>/iU';
- preg_match($mode,$text,$result);
- return $result[1];
- }
- echo '网站标题:'.$title = _title($url,$charset);
- echo "\n";
- function _keywords($url,$charset){
- $text = file_get_contents($url);
- if ($charset == 'gb2312'){
- $text = iconv('gb2312','utf-8',$text);
- }
- $mode = '/<meta\s+name=\"keywords\"\s+content=\"(.*)\"\s?\/?>/iU';
- preg_match($mode,$text,$result);
- return $result[1];
- }
- echo '网站关键词:'.$keywords = _keywords($url,$charset);
- echo "\n";
- function _description($url,$charset){
- $text = file_get_contents($url);
- if ($charset == 'gb2312'){
- $text = iconv('gb2312','utf-8',$text);
- }
- $mode = '/<meta\s+name=\"description\"\s+content=\"(.*)\"\s?\/?>/iU';
- preg_match($mode,$text,$result);
- return $result[1];
- }
- echo '网站简介:'.$description = _description($url,$charset);
- }
小伙伴要是觉得麻烦可以使用爱站云的api接口:https://aizhancloud.cn/wiki/wangzhan/meta.php?url=查询域名,如配置出现问题或者不会配置的小伙伴可以联系爱站云进行付费操作~
本文来源:【网站meta信息获取 标题 关键词 描述在线获取api代码分享】
由思享SEO博客编辑转载,仅用于参考学习,如有侵权请联系本站修改删除!
扩展阅读
PHP怎么判断字符串是不是全是空格?
对于程序实现的某些功能,有时候会出现全部输入空格的情况,这种情况会导致程序报错。因此,在PHP中可以对这种情况进行提前判断反馈提示。那么如何实现呢? ctype_space()函数 ctype_space()函数是PHP中的字符类型(CType)函数......
php生成ico图标透明背景变黑的解决办法
最近发现自己的工具箱网站,图片生成ICO功能如果用的是透明背景,生成的图片会变成黑色,如果这样拿来做favicon.ico,会非常不美观的,于是在网上找到了解决办法,最后修复了这一问题,非常赞...
PHP使用header函数301重定向无法跳转是什么原因
最近解除了tag标签robots.txt封禁,但是旧url有所修改,所以打算使用header301重定向。但是在使用过程中出现跳转失败的问题,那么,一般情况下,出现这种情况可能是什么原因呢? 解决方法: 修改php.ini; 找到 output_bu......