How to obtain Baidu record, Baidu keyword, and Baidu snapshot using php

Source: Internet
Author: User
Tags echo date
This article mainly introduces how php can obtain Baidu's indexing, Baidu's buzzwords, and Baidu's snapshots. It provides examples of php's skills in capturing Baidu pages and corresponding string analysis, which is of great practical value, for more information, see the examples in this article. Share it with you for your reference. The details are as follows:

Get Baidu record:

<? Php/* capture baidu indexed code */function baidu ($ s) {$ baidu = "http://www.baidu.com/s? Wd = site % 3A ". $ s; $ site = file_get_contents ($ baidu); // $ site = iconv ("gb2312", "UTF-8", $ site); ereg ("locate related webpage (. *), ", $ site, $ count); $ count = str_replace (" find related webpage "," ", $ count); $ count = str_replace, "," ", $ count); $ count = str_replace (" approx "," ", $ count); $ count = str_replace (",","", $ count); return $ count [0];} echo baidu (www.bitsCN.com); // Obtain the number of entries indexed in baidu?>

Get Baidu's buzzwords

<? Php/*** @ return array return Baidu's popular word data (array return) */function getBaiduHotKeyWord () {$ templateRss = file_get_contents ('http: // top.baidu.com/rss_xml.php? P = top10'); if (preg_match ('/

This is a slight modification found on the internet. write the following code into the php file.
Baidu record and Baidu snapshot time

<? Php $ domain = "http://www.bitsCN.com/* domain name to query */$ 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';/* domain name's URL indexed today */$ utf_pattern = "/find the number of results (. *)/"; $ 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);/* Change site: put the webpage www.bitsCN.com into the $ s0 string */$ s1 = @ file_get_contents ($ today); preg_match ($ utf_pattern, $ s0, $ all_num ); /* match "find the number of related results *" */preg_match ($ utf _ 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   
(. *) <\/Table>/is ', $ templateRss, $ _ description) {$ templateRss =$ _ description [0]; $ templateRss = str_replace ("&", "&", $ templateRss) ;}$ templateRss = "<? Xml version = 1.0 encoding = GBK?> ". $ TemplateRss; $ xml = @ simplexml_load_String ($ templateRss); foreach ($ xml-> tbody-> tr as $ temp) {if (! Empty ($ temp-> td-> a) {$ keyArray [] = trim ($ temp-> td-> a) ;}} return $ keyArray ;} print_r (getBaiduHotKeyWord ());
Date Baidu Baidu recorded today Baidu snapshot date
<? Php echo date ('m month D Day G time');?> <? Php echo $ all_num [1];?> <? Php echo $ today_num [1];?> <? Php echo $ screenshot [0];?>

Baidu: "target =" _ blank "> <? Php echo $ all_num [1];?>

Baidu recorded today: "target =" _ blank "> <? Php echo $ today_num [1];?>

Baidu snapshot date: "> <? Php echo $ screenshot [0];?>

I hope this article will help you with php programming.

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.