Home >Backend Development >PHP Tutorial >PHP implementation to check whether the article is included in Baidu, _PHP tutorial

PHP implementation to check whether the article is included in Baidu, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:531207browse

php implementation to check whether the article is included in Baidu,

Every website has a backend, which publishes news and products. After publishing, if you want to check whether the page has been included in Baidu, you have to use a third-party tool or directly search on Baidu. I am doing SEO recently, and every day I have to check whether the articles I posted the day before have been included. This is a very tedious job. So I found a piece of code on the Internet. It is very convenient to know whether it has been included in Baidu through the address.


The following is the PHP code

Copy code The code is as follows:

Function checkBaidu($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, ''.$arr['query'].'')) {
Return 1;
} else {
Return 0;
}
}
echo checkBaidu('www.jb51.net');

The return result is 1 for inclusion. If it is 0, it is not included.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/948406.htmlTechArticlephp implements checking whether the article is included in Baidu. The website has a backend, and the backend publishes news and products. If you want to check whether the page has been indexed by Baidu, you also need to go through the third...
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