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

yipeiwu_com5年前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树的深度编历生成迷宫及A*自动寻路算法实例分析

本文实例讲述了PHP树的深度编历生成迷宫及A*自动寻路算法。分享给大家供大家参考。具体分析如下: 有一同事推荐了三思的迷宫算法,看了感觉还不错,就转成php 三思的迷宫算法是采用树的深度...

php中html_entity_decode实现HTML实体转义

最近遇到一个问题,数据中包含中文引号,结果被转义存储到数据库,取数据的时候用了htmlspecialchars_decode把实体转义回去,结果发现并没有生效,看了一下htmlspeci...

PHP使用PDO调用mssql存储过程的方法示例

本文实例讲述了PHP使用PDO调用mssql存储过程的方法。分享给大家供大家参考,具体如下: 数据库中已创建存储过程user_logon_check, PHP调用示例如下, <...

php中call_user_func函数使用注意事项

本文实例讲述了php中call_user_func函数使用注意事项。分享给大家供大家参考。具体分析如下: call_user_func函数的注意事项:parse error: synta...

PHP防盗链的基本思想 防盗链的设置方法

盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务提供商的服务内容,骗取最终用户的浏览和点击率。受益者不...