Php: getting Baidu indexing and snapshot code _ PHP Tutorial

Source: Internet
Author: User
Php allows you to obtain Baidu's indexing and snapshot code. This article introduces how to use php to obtain baidu snapshots and collect code. let's take a look at the applications in this instance of php's functions and encoding conversion functions. Let's take a look at this article to introduce how to use php to obtain baidu snapshots and collect code. let's take a look at the applications in this instance of php's functions and encoding conversion functions.

First, let's take a look at the effect code as follows:

The code is as follows:

$ Domain = "www.hzhuti.com";/* domain name to be queried */
$ Site_url = 'http: // www.baidu.com/s? Wd = site % 3A ';
$ All = $ site_url. $ domain;/* all URLs included in the domain name */
$ Today = $ all. '& lm = 1';/* url of the domain name recorded today */
$ Utf_pattern = "/find the number of related results /";
$ Gb2312_pattern = iconv ("UTF-8", "GB2312", $ utf_pattern);/* because Baidu is GB2312 encoded */
$ Kz_pattern = "/(. *)/";/* string used to match the snapshot date */
$ Times = "/d {4}-d {1, 2}-d {1, 2}/";/* match the regular expression of the snapshot date, for example, 2011-8-4 */
$ S0 = @ file_get_contents ($ all);/* place the website: www.hzhuti.com into the $ s0 string */
$ S1 = @ file_get_contents ($ today );
Preg_match ($ gb2312_pattern, $ s0, $ all_num);/* match "find the number of related results "*/
Preg_match ($ gb2312_pattern, $ s1, $ today_num );
Preg_match ($ kz_pattern, $ s0, $ temp );
Preg_match ($ times, $ temp [0], $ screenshot );
If ($ all_num [1] = "")
$ All_num [1] = 0;
If ($ today_num [1] = "")
$ Today_num [1] = 0;
If ($ screenshot [0] = "")
$ Screenshot [0] = "no snapshot ";
?>


Test


Baidu: "target =" _ blank ">


Baidu today: "target =" _ blank ">


Baidu snapshot date: ">



Bytes. Let's take a look...

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.