<?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/