This article describes the PHP to get Baidu included, Baidu hot words and Baidu snapshot method. Share to everyone for your reference. Specifically as follows:
Get Baidu included:
<?php
/* Crawl Baidu included 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 the relevant page (. *),", $site, $count);
$count =str_replace ("Find the relevant page", "", $count);
$count =str_replace ("article,", "", $count);
$count =str_replace ("About", "", $count);
$count =str_replace (",", "", $count);
return $count [0];
}
echo Baidu (www.jb51.net);
Get the number of cloud-dwelling communities in Baidu
?>
Get the hot word of Baidu
<?php
/**
* @return Array returns the hot Word data (array return) of Baidu/
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->a)) {
$keyArray [] = Trim (($temp-> Td->a));
}
return $keyArray;
}
Print_r (Getbaiduhotkeyword ());
It was found on the Internet, slightly modified. Write the following code to the PHP file
Baidu included and Baidu snapshot time
<?php $domain = "http://www.jb51.net/* to query the domain name */$site _url = ' Http://www.baidu.com/s?wd=site%3A '; $all = $site _url. $domain; * * Domain name all included in the URL * * * $today = $all. ' &lm=1′;
* * Domain name today included in the URL * * * $utf _pattern = "/Find the number of related results (. *)/"; $kz _pattern = "/<span class=" G "> (. *) </span>/"; /* The string used to match the snapshot date * * * $times = "/d{4}-d{1,2}-d{1,2}/"; /* A regular expression that matches the snapshot date, such as: 2011-8-4*/$s 0 = @file_get_contents ($all);
/* Place the Site:www.jb51.net Web page into the $s0 string/$s 1 = @file_get_contents ($today); Preg_match ($utf _pattern, $s 0, $all _num);
/* Match "Find related result number *" * * Preg_match ($utf _pattern, $s 1, $today _num);
Preg_match ($kz _pattern, $s 0, $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";?>
I hope this article will help you with your PHP programming.