Home  >  Article  >  Database  >  PHP generates RSS file class example code

PHP generates RSS file class example code

怪我咯
怪我咯Original
2017-07-11 16:35:151423browse

RSS (Really Simple Syndication): It is a news source format specification used for websites that publish frequently updated data, such as blog posts, news, audio or video Pick. An RSS file (also called a summary, network summary, or frequency update, provided to a channel) contains full text or excerpted text, plus excerpts from the network to which the user subscribes and authorized content. metadata. Web summaries enable publishers to automatically publish their data, while also enabling readers to regularly update their favorite sites or aggregate web summaries from different sites. RSS summaries can be read through RSS readers, feed readers, aggregators and other web pages or desktop-based software. Standard XML files allow information to be published once and viewed by different programs. Users subscribe to web excerpts by entering the web excerpt into an RSS reader or using the mouse to click on the URI (not commonly known as the URL) of the small RSS icon on the browser that points to the subscription program. The RSS reader periodically checks for updates and then downloads them to the monitoring user interface. RSS can be the abbreviation of any of the following three explanations, but in fact all three refer to the same syndication technology: This article mainly introduces PHP generates RSS file class, which can realize the function of PHP generating RSS files. It has certain practical value for website construction and optimization. Friends in need can refer to the

PHP RSS generation class example code as follows:

The code is as follows:

<?php 
if (defined(&#39;_class_rss_php&#39;)) return; 
define(&#39;_class_rss_php教程&#39;,1); 

class rss { 
   //public 
   $rss_ver = "2.0"; 
   $channel_title = &#39;&#39;; 
   $channel_link = &#39;&#39;; 
   $channel_description = &#39;&#39;; 
   $language = &#39;zh_cn&#39;; 
   $copyright = &#39;&#39;; 
   $webmaster = &#39;&#39;; 
   $pubdate = &#39;&#39;; 
   $lastbuilddate = &#39;&#39;; 
   $generator = &#39;redfox rss generator&#39;; 
 
   $content = &#39;&#39;; 
   $items = array(); 
 
   function rss($title, $link, $description) { 
       $this->channel_title = $title; 
       $this->channel_link = $link; 
       $this->channel_description = $description; 
       $this->pubdate = date(&#39;y-m-d h:i:s&#39;,time()); 
       $this->lastbuilddate = date(&#39;y-m-d h:i:s&#39;,time()); 
   } 
 
   function additem($title, $link, $description ,$pubdate) { 
       $this->items[] = array(&#39;titile&#39; => $title , 
                        &#39;link&#39; => $link, 
                        &#39;description&#39; => $description, 
                        &#39;pubdate&#39; => $pubdate); 
   } 
 
   function buildrss() { 
       $s = "<!--l version="1.0" encoding="gb2312"--> "; 
       // start channel 
       $s .= " "; 
       $s .= " " 
       $s .= "<link />{$this->channel_link} "; 
       $s .= "{$this->channel_description} "; 
       $s .= "{$this->language} "; 
       if (!emptyempty($this->copyright)) { 
          $s .= "{$this->copyright} "; 
       } 
       if (!emptyempty($this->webmaster)) { 
          $s .= "{$this->webmaster} "; 
       } 
       if (!emptyempty($this->pubdate)) { 
          $s .= "{$this->pubdate} "; 
       } 
 
       if (!emptyempty($this->lastbuilddate)) { 
          $s .= "{$this->lastbuilddate} "; 
       } 
 
       if (!emptyempty($this->generator)) { 
          $s .= "{$this->generator} "; 
       } 
       
       // start items 
       for ($i=0;$iitems),$i++) { 
           $s .= " "; 
           $s .= " "; 
           $s .= "<link />{$this->items[$i][&#39;link&#39;]} "; 
           $s .= "<!--data[{$thi-->items[$i][&#39;description&#39;]}]]> "; 
           $s .= "{$this->items[$i][&#39;pubdate&#39;]} ";           
           $s .= " "; 
       } 
      
      // close channel 
      $s .= " "; 
      $this->content = $s; 
   } 
 
   function show() { 
       if (emptyempty($this->content)) $this->buildrss(); 
       header(&#39;content-type:text/xml&#39;); 
       echo($this->content); 
   } 
 
   function savetofile($fname) { 
       if (emptyempty($this->content)) $this->buildrss(); 
       $handle = fopen($fname, &#39;wb&#39;); 
       if ($handle === false)  return false; 
       fwrite($handle, $this->content); 
       fclose($handle); 
   } 
} 
?>

The above is the detailed content of PHP generates RSS file class example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn