PHP在线一键获取网站meta信息代码

PHP与SEO 投稿&转载 703浏览

本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=查询域名,如配置出现问题或者不会配置的小伙伴可以联系爱站云进行付费操作~

推荐阅读

PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。...

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...

百度自动推送php实现代码

我们知道主动推送有助于搜索引擎抓取和收录网站内容,wordpress或者主流CMS其实已经集成了推送功能。但是如果我们要定期归还,而不是只在发布的时候推一次。这个功能可以通过结合PHP和Pagoda Panel的预定任务来实现。$api = '百度站......