Get started: (Recommended learning: PHP programming from entry to proficiency)
$url = 'https://www.yeguobiji.com/; echo checkBaidu($url); //如果输出1表示已经收录,-1表示没收录
We can Determine whether the URL is included based on the return value of the checkBaidu method.
/** * PHP检测url地址是否被百度收录 * @param string $url 要检测的URL地址 */ public 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; } }
The above is the detailed content of PHP determines whether the URL is included in Baidu. For more information, please follow other related articles on the PHP Chinese website!