Home  >  Article  >  Backend Development  >  php改良判断网站是不是被百度收录

php改良判断网站是不是被百度收录

WBOY
WBOYOriginal
2016-06-13 12:15:071385browse

php改良判断网站是否被百度收录
在网上浏览php程序时 发现了这样一篇文章:php使用curl检测网页是否被百度收录的示例分享

http://www.jb51.net/article/46430.htm

作者很娴熟的运用curl来对网站是否被百度收录做出了判断,但是同样存在代码过于冗长的缺点,我冒昧的进行了改进:

原:

<?php /** 检测百度是否收录网页 curl模式* @ param string $url传入的url* return int (1 收录 0 不收录)*/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>'.$arr['query'].'')){return 1;}else{return 0;} }echo checkBaidu('http://www.jb51.net/');?>

改:
<?phpfunction checkbaidu($url){	$str=file_get_contents("http://wap.baidu.com/s?word=inurl:".$url);//加快速度,用WAP网页来进行搜索,并且应用搜索引擎的inurl语法	if(stripos($str,"抱歉,没有找到"))return 0;//如果出现关键字则判定没有找到		return 1;}echo checkbaidu("aaaaas.cc");?>

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