Home > Backend Development > PHP Tutorial > php如何判断网页是否被百度收录了?

php如何判断网页是否被百度收录了?

WBOY
Release: 2016-06-20 13:03:25
Original
1104 people have browsed it

运用php的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>&#39;.$arr[&#39;query&#39;].&#39;</b>&#39;)){
return 1;
}else{
return 0;
} 
}
echo checkBaidu(&#39;http://www.scutepp.com/&#39;);
?>
Copy after login

 


Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template