今天利用网上的资料,给之前写的站点小工具加上百度谷歌收录,后来发现因为谷歌被墙,导致查询出错。然后我就去网上搜索了一下,发现了 k780数据 提供收录查询API,于是折腾了一会。

k780数据提供的文档说明简洁明了,我采用了XML格式来获取收录。XML的API格式为:

http://api.k780.com:88/?app=entry.baidu&website=域名&appkey=密匙&sign=标识&format=xml

代码

//百度收录
function get_baidu() {
	$domain = $_SERVER['HTTP_HOST'];
	$site_url = "http://api.k780.com:88/?app=entry.baidu&domain=$domain&appkey=*****&sign=*****&format=xml";
	$utf_pattern = "/\<entry\>(.*)\<\/entry\>/";
	$html = file_get_contents($site_url);
	preg_match($utf_pattern,$html,$all_num);
	if($all_num[1] == "") $all_num[1] = 0;
	return str_replace(" ", "", str_replace(",","", $all_num[1]));
}

//谷歌收录
function get_google(){
	$domain = $_SERVER['HTTP_HOST'];
	$site_url = "http://api.k780.com:88/?app=entry.google&domain=$domain&appkey=*****&sign=*****&format=xml";
	$utf_pattern = "/\<entry\>(.*)\<\/entry\>/";
	$html = file_get_contents($site_url);
	preg_match($utf_pattern,$html,$all_num);
	if($all_num[1] == "") $all_num[1] = 0;
	return str_replace(" ", "", str_replace(",","", $all_num[1]));
}
转载保留版权:http://haipz.com/blog/i/6043 - 海胖博客