Home > php教程 > PHP源码 > body text

检测页面是否被百度收录

PHP中文网
Release: 2016-05-25 17:06:21
Original
1853 people have browsed it

[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;);
    ?>
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template