Home >php教程 >PHP源码 >检测页面是否被百度收录

检测页面是否被百度收录

PHP中文网
PHP中文网Original
2016-05-25 17:06:211889browse

[PHP]代码   

    <?php
    /*
    * 检测百度是否收录网页 返回1则表示收录 返回0表示没有收录
    * @ param string $url传入的url
    *  powed by 回首
    */
    function checkBaidu($url){
        $url=&#39;http://www.baidu.com/s?wd=&#39;.$url;
          
        $curl=curl_init();
        curl_setopt($curl,CURLOPT_URL,$url);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
        $rs=curl_exec($curl);
        curl_close($curl);
          
        $arr=parse_url($url);
          
        if(strpos($arr[&#39;query&#39;],&#39;http://&#39;)){
            $arr[&#39;query&#39;]=str_replace(&#39;http://&#39;,&#39;&#39;,str_replace(&#39;wd=&#39;,&#39;&#39;,$arr[&#39;query&#39;]));
        }else{
            $arr[&#39;query&#39;]=str_replace(&#39;wd=&#39;,&#39;&#39;,$arr[&#39;query&#39;]);
        }
          
        if(strpos($arr[&#39;query&#39;],&#39;?&#39;)){
            $str=strstr($arr[&#39;query&#39;],&#39;?&#39;);
            $arr[&#39;query&#39;]=str_replace($str,&#39;&#39;,$arr[&#39;query&#39;]);
        }
          
        if(strpos($arr[&#39;query&#39;],&#39;/&#39;)){
            $narr=explode(&#39;/&#39;,$arr[&#39;query&#39;]);
            $arr[&#39;query&#39;]=$narr[0];
        }
          
        if(strpos($rs,&#39;<b>&#39;.$arr[&#39;query&#39;].&#39;</b>&#39;)){
            return 1;
        }else{
            return 0;
        }   
    }
      
    echo checkBaidu(&#39;http://www.adfsdfsdf.com/&#39;);
    ?>

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:CURL封装类Next article:天天AV - 微信公众平台 - 实例