Home  >  Article  >  php教程  >  查看某个网址是否被百度收录

查看某个网址是否被百度收录

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

php代码

<?php
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.phpsblogs.com/archives/category/javascript&#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