国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

PHP 實現RSS訂閱類

瀏覽:2日期:2022-09-12 16:57:57

?<?phpclass RSS{ /** +---------------------------------------------------------- * RSS頻道名 +---------------------------------------------------------- */ protected $channel_title = ’’; /** +---------------------------------------------------------- * RSS頻道鏈接 +---------------------------------------------------------- */ protected $channel_link = ’’; /** +---------------------------------------------------------- * RSS頻道描述 +---------------------------------------------------------- */ protected $channel_description = ’’; /** +---------------------------------------------------------- * RSS頻道使用的小圖標的URL +---------------------------------------------------------- */ protected $channel_imgurl = ’’; /** +---------------------------------------------------------- * RSS頻道所使用的語言 +---------------------------------------------------------- */ protected $language = ’zh_CN’; /** +---------------------------------------------------------- * RSS文檔創建日期,默認為今天 +---------------------------------------------------------- */ protected $pubDate = ’’; protected $lastBuildDate = ’’; protected $generator = ’YBlog RSS Generator’; /** +---------------------------------------------------------- * RSS單條信息的數組 +---------------------------------------------------------- */ protected $items = array(); /** +---------------------------------------------------------- * 構造函數 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $title RSS頻道名 * @param string $link RSS頻道鏈接 * @param string $description RSS頻道描述 * @param string $imgurl RSS頻道圖標 +---------------------------------------------------------- */ public function __construct($title, $link, $description, $imgurl = ’’) {$this->channel_title = $title;$this->channel_link = $link;$this->channel_description = $description;$this->channel_imgurl = $imgurl;$this->pubDate = Date(’Y-m-d H:i:s’, time());$this->lastBuildDate = Date(’Y-m-d H:i:s’, time()); } /** +---------------------------------------------------------- * 設置私有變量 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $key 變量名 * @param string $value 變量的值 +---------------------------------------------------------- */ public function Config($key,$value) {$this->{$key} = $value; } /** +---------------------------------------------------------- * 添加RSS項 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $title 日志的標題 * @param string $link 日志的鏈接 * @param string $description 日志的摘要 * @param string $pubDate 日志的發布日期 +---------------------------------------------------------- */ function AddItem($title, $link, $description, $pubDate) {$this->items[] = array(’title’ => $title, ’link’ => $link, ’description’ => $description, ’pubDate’ => $pubDate); } /** +---------------------------------------------------------- * 輸出RSS的XML為字符串 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ public function Fetch() {$rss .= '<?xml version='1.0' encoding='utf-8' ?>rn';$rss .= '<rss version='2.0'>rn';$rss .= '<channel>rn';$rss .= '<title><![CDATA[{$this->channel_title}]]></title>rn';$rss .= '<description><![CDATA[{$this->channel_description}]]></description>rn';$rss .= '<link>{$this->channel_link}</link>rn';$rss .= '<language>{$this->language}</language>rn'; if (!empty($this->pubDate)) $rss .= '<pubDate>{$this->pubDate}</pubDate>rn';if (!empty($this->lastBuildDate)) $rss .= '<lastBuildDate>{$this->lastBuildDate}</lastBuildDate>rn';if (!empty($this->generator)) $rss .= '<generator>{$this->generator}</generator>rn'; $rss .= '<ttl>5</ttl>rn'; if (!empty($this->channel_imgurl)) { $rss .= '<image>rn'; $rss .= '<title><![CDATA[{$this->channel_title}]]></title>rn'; $rss .= '<link>{$this->channel_link}</link>rn'; $rss .= '<url>{$this->channel_imgurl}</url>rn'; $rss .= '</image>rn';} for ($i = 0; $i < count($this->items); $i++) { $rss .= '<item>rn'; $rss .= '<title><![CDATA[{$this->items[$i][’title’]}]]></title>rn'; $rss .= '<link>{$this->items[$i][’link’]}</link>rn'; $rss .= '<description><![CDATA[{$this->items[$i][’description’]}]]></description>rn'; $rss .= '<pubDate>{$this->items[$i][’pubDate’]}</pubDate>rn'; $rss .= '</item>rn';} $rss .= '</channel>rn</rss>';return $rss; } /** +---------------------------------------------------------- * 輸出RSS的XML到瀏覽器 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ public function Display() {header('Content-Type: text/xml; charset=utf-8');echo $this->Fetch();exit; }}

?>

標簽: PHP
相關文章:
主站蜘蛛池模板: 南阳市| 济阳县| 舟山市| 万盛区| 公安县| 酉阳| 宁海县| 当涂县| 北宁市| 乌拉特中旗| 泰和县| 全州县| 抚远县| 甘洛县| 宁都县| 泸定县| 寻甸| 鸡泽县| 邵东县| 水富县| 保亭| 星座| 泰州市| 石城县| 右玉县| 额尔古纳市| 平湖市| 高阳县| 独山县| 丽江市| 葫芦岛市| 平泉县| 新蔡县| 二连浩特市| 迁安市| 准格尔旗| 绵竹市| 美姑县| 南木林县| 丰宁| 肃宁县|