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

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

PHP 實現RSS訂閱類

瀏覽:6日期: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
相關文章:
主站蜘蛛池模板: 台中市| 册亨县| 长顺县| 德化县| 吉林省| 海宁市| 琼海市| 蒲城县| 方正县| 新宾| 阿图什市| 卢龙县| 南开区| 门源| 萨嘎县| 昌宁县| 桐乡市| 鸡泽县| 松阳县| 灵台县| 福鼎市| 遵化市| 嘉鱼县| 工布江达县| 馆陶县| 濮阳县| 大化| 克山县| 安阳市| 祁门县| 兴化市| 商城县| 谢通门县| 萨嘎县| 安化县| 梅河口市| 竹北市| 南宁市| 集贤县| 察雅县| 夏邑县|