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('_class_rss_php')) return; define('_class_rss_php教程',1); class rss { //public $rss_ver = "2.0"; $channel_title = ''; $channel_link = ''; $channel_description = ''; $language = 'zh_cn'; $copyright = ''; $webmaster = ''; $pubdate = ''; $lastbuilddate = ''; $generator = 'redfox rss generator'; $content = ''; $items = array(); function rss($title, $link, $description) { $this->channel_title = $title; $this->channel_link = $link; $this->channel_description = $description; $this->pubdate = date('y-m-d h:i:s',time()); $this->lastbuilddate = date('y-m-d h:i:s',time()); } function additem($title, $link, $description ,$pubdate) { $this->items[] = array('titile' => $title , 'link' => $link, 'description' => $description, 'pubdate' => $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]['link']} "; $s .= "<!--data[{$thi-->items[$i]['description']}]]> "; $s .= "{$this->items[$i]['pubdate']} "; $s .= " "; } // close channel $s .= " "; $this->content = $s; } function show() { if (emptyempty($this->content)) $this->buildrss(); header('content-type:text/xml'); echo($this->content); } function savetofile($fname) { if (emptyempty($this->content)) $this->buildrss(); $handle = fopen($fname, 'wb'); 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!