Home > 类库下载 > PHP类库 > body text

PHP detects whether the url address is included in Baidu

高洛峰
Release: 2016-10-21 10:11:50
Original
1540 people have browsed it

The following may be useful to SEO friends, or it may also be useful to manage articles edited and published by companies, so I would like to share it with you now.

/**
 * PHP检测url地址是否被百度收录
 * @param string    $url 要检测的URL地址
 */
function checkBaidu($url) { 
    $url = 'http://www.baidu.com/s?wd=' . urlencode($url); 
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
    $rs = curl_exec($curl); 
    curl_close($curl); 
    if (!strpos($rs, '没有找到')) { //没有找到说明已被百度收录 
        return 1; 
    } else { 
        return -1; 
    } 
 }
  
 
$url = 'http://liqingbo.cn/blog-385.html'; 
 
 
echo checkBaidu($url);    //如果输出1表示已经收录,-1表示没收录
Copy after login

We can determine whether the URL is included based on the return value of the checkBaidu method.

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