php 查询百度与google收录情况的实现代码
发布时间:2016-10-02 编辑:jiaochengji.com
本文介绍下,用php实现的查询百度收录、谷歌收录情况的一段代码,有需要的朋友参考下。
用php来查询百度或google的收录情况,其实并不复杂,只需要file下远程文件,然后分析相关数据即可。
以下是收录查询核心代码,getdetail函数也可以这样写,用正则去匹配:
$wordf = preg_quote($wordf); $wordb = preg_quote($wordb); $pagecontent = @preg_replace("/\s*$wordf(.+?)$wordb\s*/e", "returndetail('\\1', '$type')", $pagecontent); $pagecontent = @preg_replace("/\s*".preg_quote($wordf)."(.+?)".preg_quote($wordb)."\s*/e", "returndetail('\\1', '$type')", $pagecontent);
完整代码:
<?php /** * 查询百度与google的收录情况 * by www.jbxue.com */ $seodetail = array(); $domain = !empty($_GET['q']) ? $_GET['q'] : 'www.mycodes.net'; baidudetail($domain); googledetail($domain); var_dump($seodetail); function baidudetail($domain) { $baidu_site = 'http://www.baidu.com/baidu?word=site%3A' . $domain; $baidu_link = 'http://www.baidu.com/baidu?word=link%3A' . $domain; $baidu_domain = 'http://www.baidu.com/baidu?word=domain%3A' . $domain; getdetail($baidu_site, 'baidu_site', '相关网页', '篇,用时'); getdetail($baidu_link, 'baidu_link', '相关网页', '篇,用时'); getdetail($baidu_domain, 'baidu_domain', '相关网页', '篇,用时'); } function googledetail($domain) { $google_site = 'http://www.google.cn/search?hl=zh-CN&q=site%3A' . $domain; $google_link = 'http://www.google.cn/search?hl=zh-CN&q=link%3A' . $domain; getdetail($google_site, 'google_site', '</b> 个结果,', ' 个。 (搜索用时'); getdetail($google_link, 'google_link', '<font size=-1>约有 <b>', '</b> 项链接到 <b>');//102 } function getdetail($url, $type, $wordf, $wordb) { $pagecontent = @file($url); $pagecontent = implode('', $pagecontent); $pagecontent = substr(strstr($pagecontent, $wordf), strlen($wordf)); $pagecontent = substr_replace($pagecontent, '', strpos($pagecontent, $wordb)); returndetail($pagecontent,$type); } function returndetail($content,$type) { global $seodetail; $seodetail[$type] = empty($content) ? 0 : $content; } ?>
您可能感兴趣的文章:
php 查询百度与google收录情况的实现代码
php 获取百度收录和百度快照时间的代码
php 百度快照、百度收录、百度热词的代码分享
网站收录被google的原因是什么?
百度和google对新站的处理方式
php检测页面是否被百度收录的实例代码
怎样通过google提升网站访问量
Google的网站收录和排名浅析
seo优化baidu与google差异性
php检测url是否被百度收录示例代码
上一篇:PHP求异形多维数组的平均值的例子
下一篇:php程序员面试之百度面试题
[关闭]