The example of this article describes the PHP simple to get Baidu search and search Sogou searches methods. Share to everyone for your reference, specific as follows:
Get the site Baidu search and Sogou search of the amount of code, can be used to get the site domain name in the search engine of the number, has been looking for this API but did not find, on the Internet to find an example, learn to modify the next, you can get the normal search Baidu search and Sogou searches of the amount of collection; The principle is to obtain search engine site: The number of results in domain and then grab this number to show up.
function Baidu ($url) {
$baidu = "Http://www.baidu.com/s?wd=site:". $url;
$site =file_get_contents ($baidu);
Ereg ("The site has a total of (. *) a Web page is included in Baidu," $site, $count);
$count =str_replace ("The site is common", "", $count);
$count =str_replace ("A webpage is included in Baidu", "", $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 ("Find out about (. *) Results", $site, $count);
$count =str_replace ("Find out about", "", $count);
$count =str_replace ("Result", "", $count);
$count =str_replace (",", "", $count);
$count =str_replace ("", "", $count);
return strip_tags ($count [0]);
>
www.jb51.net Baidu included <?php Echo Baidu (' www.jb51.net ');? > <br>
www.jb51.net sogou included <?php echo sogou (' www.jb51.net ');? > Bar
The effect is as shown in the following illustration:
Note: the file encoding here requires the use of the Utf-8 format .
More about PHP Interested readers can view the site topics: "PHP Regular Expression Usage summary", "Php Curl Usage Summary", "PHP Array" operation Skills Encyclopedia, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", " PHP Data structure and algorithm tutorial, "PHP Programming Algorithm Summary", "PHP Mathematical Calculation Skills Summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.