php实现查询百度google收录情况(示例代码)

yipeiwu_com6年前PHP代码库

写了一个小东西记录baidu和google对于站点的收录情况,现在可以查询了,其实也没什么难度,就是去file下远程文件,然后分析下。

对了貌似查google pr的东西只是file一个地址而已,如此说了就没有什么难度了。
完整代码如下,file取得文件,分析,输出:

复制代码 代码如下:

<?php
$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加密函数 Javascript/Js 解密函数

以下函数代码中“123456” 是个加密的key,自己可以随便改。php加密,js解密,貌似没什么意义,主要是key在js中会被看到。不过在某些地方可能会用到。 PHP加密函数 复制代码...

php下正则来匹配dede模板标签的代码

html代码 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w...

php使用include 和require引入文件的区别

最近有小伙伴,提问了有关于require_once的有关问题,对于程序中遇到的问题,无聊难度大小,只要bug存在就还值得我们去探索,去解决。针对这个问题,我把include和requir...

php运行报错Call to undefined function curl_init()的最新解决方法

之前网上的解决方法如下: 1、在php.ini中开启curl扩展 2、将php目录下的libeay32.dll、ssleay32.dll、php5ts.dll拷贝到c:\windows\...

php select,radio和checkbox默认选择的实现方法

这是扩展yibing的select默认选择的实现方法 复制代码 代码如下: <select name="wuyeleixing" size="1"> <option &...