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实现图片上传并利用ImageMagick生成缩略图

使用ImageMagick,您可以轻松,更快地创建缩略图,比使用PHP的容易得多。 <?php // Location to upload main image: $...

PHP中CURL方法curl_setopt()函数的参数分享

PHP CURL curl_setopt 参数bool curl_setopt (int ch, string option, mixed value)curl_setopt()函数将为...

php curl发送请求实例方法

cURL可以使用URL的语法模拟浏览器来传输数据,因为它是模拟浏览器,因此它同样支持多种协议,FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT,...

微信公众平台开发教程⑥ 微信开发集成类的使用图文详解

微信公众平台开发教程⑥ 微信开发集成类的使用图文详解

本文实例讲述了微信公众平台开发之微信开发集成类的使用。分享给大家供大家参考,具体如下: 背景   这几天又在接触微信PHP方面的开发,认为之前写的文章确实有些乱,刚好发现了一...

php版交通银行网银支付接口开发入门教程

本文实例讲述了php版交通银行网银支付接口实现方法。分享给大家供大家参考,具体如下: 概述:网银支付接口 和支付宝接口大体上差不多,主要的区别是 交通银行提供的 接口核心的比如,加密等是...