PHP simple access to the site Baidu search and Sogou search methods _php Skills

Source: Internet
Author: User
Tags ereg php programming php regular expression in domain

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.