Php captures Baidu snapshots, Baidu records, Baidu keyword program code, and Baidu snapshots
<?
/*
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 ("find related webpage (. *),", $ site, $ count );
$ Count = str_replace ("find related webpage", "", $ count );
$ Count = str_replace ("article,", "", $ count );
$ Count = str_replace ("approx", "", $ count );
$ Count = str_replace (",", "", $ count );
Return $ count [0];
}
Echo baidu (www.hzhuti.com); // obtain the number of topics included in baidu
?>
Get Baidu's buzzwords
<? Php
/**
** @ User Xiaojie
* @ Return array returns Baidu's buzzword data (array return)
*/
Function getBaiduHotKeyWord ()
{
$ TemplateRss = file_get_contents ('HTTP: // top.baidu.com/rss_xml.php? P = top10 ');
If (preg_match ('/<table> (. *) </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-> )){
$ KeyArray [] = trim ($ temp-> td-> ));
}
}
Return $ keyArray;
}
Print_r (getBaiduHotKeyWord ());
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.hzhuti.com/nokia/5230/ * 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';/* the website of the domain name recorded today */
$ Utf_pattern = "/find the number of related results /";
$ Kz_pattern = "/<span class =" g "> (. *) </span>/";/* 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.ninthday.net webpage 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 ";
?>
<Html>
<Head>
<Title> Test </title>
</Head>
<Body>
<Table>
<Tr>
<Td> date </td> <td> Baidu indexing today </td> <td> Baidu snapshot date </td>
</Tr>
<Tr>
<Td> <? Php echo date ('m month D day G Time');?> </Td> <? Php echo $ all_num [1];?> </Td> <? Php echo $ today_num [1];?> </Td> <? Php echo $ screenshot [0];?> </Td>
</Tr>
</Table>
<P> Baidu: <a href = "<? Php echo $ all;?>" Target = "_ blank"> <? Php echo $ all_num [1];?> </A> </p>
<P> Baidu today: <a href = "<? Php echo $ today;?>" Target = "_ blank"> <? Php echo $ today_num [1];?> </A> </p>
<P> Baidu snapshot Date: <a href = "<? Php echo $ all;?> "> <? Php echo $ screenshot [0];?> </A> </p>
</Body>
</Html>
The above method has not been strictly considered. If the server does not support the file_get_contents function, we will not be able to operate it. Therefore, you can also use curl to operate it, which is more convenient for Imitating users.