PHP Curl Check whether the Web page is included in Baidu

Source: Internet
Author: User
Tags curl
<?php * * Check whether Baidu is included in the page Curl mode * @ param string $url the incoming URL * return int (1 included 0 not included) * * Function Checkbai   
       
Du ($url) {$url = ' http://www.baidu.com/s?wd= '. $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 [' Query '], ' http://')) {$arr [' query ']=str_replace (' http://', ', ', Str_replace (' wd= ', ', ', $arr [' query '])   
);   
}else{$arr [' Query ']=str_replace (' wd= ', ', ', $arr [' query ']]; if (Strpos ($arr [' Query '], '? '))   
{$str =strstr ($arr [' Query '], '? ');   
$arr [' Query ']=str_replace ($str, ', $arr [' query ']];   
if (Strpos ($arr [' Query '], '/')} {$narr =explode ('/', $arr [' query ']);   
$arr [' Query ']= $narr [0]; if (Strpos $rs, ' <b> '. $arr [' query ']. '   
</b> ') {return 1;   
}else{return 0;   
} Echo Checkbaidu (' http://www.bianceng.cn/'); ?>

The other is the most painful way to do the same as pictured

The Preg_match function can be used to detect whether there is "sorry, not found with" this text to determine whether the included

function Checkbaidu ($key) {   
        $url = "http://www.baidu.com/s?wd=". $key;   
        $html = @file_get_contents ($url);   
        $html = Iconv (' utf-8 ', ' gbk//translit ', $html);   
        if (Preg_match (sorry, not found with)/', $html)) {return   
          0;   
        } else {return   
                 1;   
        }   
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.