This article mainly introduces PHP's simple method to obtain the website's Baidu search and Sogou search included volume, involving related operating skills of reading PHP web page files and regular replacement. Friends in need can refer to it. I hope it will be helpful to everyone.
The details are as follows:
Get the index code of Baidu search and Sogou search of the website, which can be used to obtain the number of indexes of the website domain name in the search engine. I have always wanted to find this API but couldn't find it. I found an example on the Internet, studied and modified it, and can now obtain the included volume of Baidu search and Sogou search normally; the principle is to obtain the number of results of the search engine site:domain, and then crawl and display this number.
function baidu($url){ $baidu="http://www.baidu.com/s?wd=site:".$url; $site=file_get_contents($baidu); ereg("该网站共有(.*)个网页被百度收录", $site,$count); $count=str_replace("该网站共有","",$count); $count=str_replace("个网页被百度收录","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } function sogou($url){ $sogou="http://www.sogou.com/web?query=site:".$url; $site=file_get_contents($sogou); ereg("找到约 (.*) 条结果", $site,$count); $count=str_replace("找到约","",$count); $count=str_replace("条结果","",$count); $count=str_replace(",","",$count); $count=str_replace(" ","",$count); return strip_tags($count[0]); } ?> www.php.cn 百度收录<?php echo baidu('www.php.cn');?>条<br> www.php.cn 搜狗收录<?php echo sogou('www.php.cn');?>条
Note: The file encoding here needs to use utf-8 format.
Related recommendations:
PHP WeChat development to obtain city weather
PHP WeChat development translation function
PHP’s powerful CURL POST class
The above is the detailed content of PHP simple method to obtain the website's Baidu and Sogou included numbers. For more information, please follow other related articles on the PHP Chinese website!