PHP to get Baidu included, Baidu hot words and Baidu Snapshot method _php skills

Source: Internet
Author: User
Tags echo date php programming

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.

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.