• 用PHP实现站长工具中查询google,百度收录情况的功能
  • 发布于 2个月前
  • 415 热度
    0 评论
  • Laughing
  • 0 粉丝 36 篇博客
  •   
 下面是代码,对了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);
完整代码如下,file取得文件,分析,输出
< ?php
$seodetail = array();
$domain = !empty($_GET['q']) ? $_GET['q'] : 'www.ccvita.com';

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<br />
}<br />
<br />
function getdetail($url, $type, $wordf, $wordb) {<br />
        $pagecontent = @file($url);<br />
        $pagecontent = implode('', $pagecontent);<br />
        $pagecontent = substr(strstr($pagecontent, $wordf), strlen($wordf));<br />
        $pagecontent = substr_replace($pagecontent, '', strpos($pagecontent, $wordb));<br />
        returndetail($pagecontent,$type);<br />
}<br />
<br />
function returndetail($content,$type) {<br />
        global $seodetail;<br />
        $seodetail[$type] = empty($content) ? 0 : $content;<br />
}<br />
?></b></font>


用户评论