首頁 php教程 php手册 rss2生成类

rss2生成类

Jun 21, 2016 am 09:05 AM
channel gt lt this

rss

  • php/**//* * @(#)Rss2Gen.inc.php (beta) 2005/2/19 *  * exblog RSS2 生成类,实现了RSS2规范中的大部分内容。 *  * 使用方法请见本类底部(Rss2Gen类使用注释)信息。 * * 本程序为免费程序,源代码使用者可任意更改(请勿用于商业用途),但请保留本版权信息! *  * @author  HexUzHoNG <hexuzhong> * @version beta-2, 2005-03-11 * @since   exBlog-1.3.0 * */ class Rss2Gen {    var $rss_header;  //RSS文档头,存放一个<rss>根元素及其version属性。  var $item;    //  var $items; var $channel_header; //频道的头部信息,存放频道名称、URL、描述、语言、版权等等。 //--------------- 以下元素是可选的频道子元素 --------------// var $channel_language; //频道使用的语言种类,例如en-us、zh-cn等,放便聚集器组织中一语言的站点。 var $channel_copyright; //频道内容的版权声明。 var $channel_managingEditor; //对该频道内容负责的个人的Email地址 var $channel_webMaster;   //对该频道的技术支持负责的个人的Email地址 var $channel_pubDate;   //该频道内容的公布日期 var $channel_lastBuildDate;  //上次频道内容更改的时间 var $channel_category;   //说明频道属于哪一个或多个分类 var $channel_generator = "<generator>exblog RSS2 builder</generator>"; //用于生成该频道的程序 var $channel_docs;   //RSS文件所使用格式的说明文档所在的URL var $channel_cloud;   //允许进程注册为“cloud”,频道更新时通知它 var $channel_ttl;   //ttl 代表存活时间,存活时间是一个数字,表示提要在刷新之前缓冲的分钟数 var $channel_image;   //指定一个能在频道中显示的GIF、JPEG 或PNG 图像 //var $channel_rating;  //关于该频道的 PICS 评价 //var $channel_textInput;  //定义可与频道一起显示的输入框 //var $channel_skipHours;  //告诉聚集器哪些小时的更新可以忽略 //var $channel_skipDays;  //告诉聚集器那一天的更新可以忽略  var $channel;   //整个rss2文档信息,用与生成整个页面。  var $halt_on_error = true;   /**//**    * 构造函数,其参数皆为rss2必须的频道子元素,如果不填,则为默认内容。   *    * @param String $title 频道的名称,频道的title应该和web站点的title尽量一致。   * @param String $link 与该频道关联的web站点的URL。   * @param String $description 对频道的一段简单描述,如介绍频道是做什么的。   * @access public   */  function Rss2Gen() {  $this->fillHeader();  }    /**//**   * 生成RSS文档头,必须以一个<rss>元素作为根元素,其有一个强制属性version,指定当前文档遵守的RSS版本。   * @access private   */  function fillHeader() {   $this->rss_header = "</rss></rss></hexuzhong>
    登入後複製
    <font face="新宋体"><span style="BORDER-BOTTOM: #ffffff 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000bb"></span><span style="COLOR: #0000bb">xml</span><span style="COLOR: #0000bb"> </span><span style="COLOR: #0000bb">version</span><span style="COLOR: #007700">=</span><span style="COLOR: #007700">"</span><span style="COLOR: #0000bb">1</span><span style="COLOR: #0000bb">.</span><span style="COLOR: #0000bb">0</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb"> </span><span style="COLOR: #0000bb">encoding</span><span style="COLOR: #0000bb">=</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb">gb2312</span><span style="COLOR: #0000bb">"</span><span style="COLOR: #0000bb">?></span></span><br></font>
    rn";   $this->rss_header .= " <rss version="2.0">rn";  }  /**//**  * 设置频道头,其中三个元素为必须的。  * @param String $title 频道的名称,频道的title应该和Web站点的title尽量一致。  * @param String $link 与该频道关联的Web站点或者站点区域的URL。  * @param String $description 对频道的一段简单描述,简要介绍频道是做什么的。  */ function setChannel($title = "exblog", $link = "http://www.exblog.org", $description = "exblog") {  $this->channel_header = "  <title></title>n";   $this->channel_header .= "  <link>".$link."rn";   $this->channel_header .= "  <description></description>rn"; }  function halt($msg) {  if ($this->halt_on_error) {   $this->haltmsg($msg);  }  die("exblog RSS2 exit"); }  function haltmsg($msg) {  sprintf("<b>exblog RSS2 builder ERROR: %s</b><br>rn", $msg); }  /**//**  * 设置该RSS文档的语言,默认为简体中文。  * @access public  */  function setLanguage($lang = "zh_cn") {   $this->channel_language = "  <language>".$lang."</language>rn";   }   /**//**  * 频道内容的版权声明  * @access public  */  function setCopyright($copyright = "exblog") {   $this->channel_copyright = "  <copyright>".$copyright."</copyright>rn";  }   /**//**  * 对该频道内容负责的个人的Email地址  * @access public  */  function setManagingEditor($email = NULL) {   if (empty($email)) {    $this->halt("如果你设置了该频道内容负责的个人的Email地址,请填写她。");   }   $this->channel_managingEditor = "  <managingeditor>".$email."</managingeditor>rn";  }   /**//**  * 对该频道的技术支持负责的个人的Email地址  * @access public  */  function setWebMaster($email = NULL) {   if (empty($email)) {    $this->halt("如果你设置了该频道的技术支持负责的个人的Email地址,请填写她。 :)");   }   $this->channel_webMaster = "  <webmaster>".$email."</webmaster>rn";  }  /**//**  * 该频道内容的公布日期。  * @access public  */  function setPubDate($date = NULL) {   if (empty($date)) {   $date = date("Y/m/d");    $this->channel_pubDate = "  <pubdate>".$date."</pubdate>rn";   }   $this->channel_pubDate = "  <pubdate>".$date."</pubdate>rn";  }   /**//**  * 上次频道内容更改的时间  * @access public  */  function setLastBuildDate($date = NULL) {  if (empty($date)) {   $date = date("Y/m/d");     $this->channel_lastBuildDate = "  <lastbuilddate>".$date."</lastbuilddate>rn";   }   $this->channel_lastBuildDate = "  <lastbuilddate>".$date."</lastbuilddate>rn";  } /**//**  * 说明频道属于哪一个或多个分类  * @access public  */  function setCategory($category) {   $this->channel_category = "  <category>".$category."</category>rn";  }  /**//**  * RSS文件所使用格式的说明文档所在的URL  * @access public  */  function setDocs($url) {   $this->channel_docs = "  <docs>".$url."</docs>rn";  }  /**//**  * ttl 代表存活时间,存活时间是一个数字,表示提要在刷新之前缓冲的分钟数  * @access public  */  function setTtl($minute) {   $this->channel_ttl = "  <ttl>".$minute."</ttl>rn";  }  /**//**  * 指定一个能在频道中显示的GIF、JPEG 或PNG 图像  *  * @param String $url 必需,是表示该频道的 GIF、JPEG 或 PNG 图像的URL  * @param String $title 必需,是图象的描述。当频道以 HTML 呈现时,用作 HTML <image> 标签的 ALT 属性。  * @param String $link 必需,是站点的 URL。如果频道以 HTML 呈现,该图像作为到这个站点的链接。  * @param Integer $width 表示图象的像素宽,必须和 $height 一同设置,否则不会显示此属性。  * @param Integer $height 表示图象的像素高,必须和 $width 一同设置,否则不会显示此属性。  * @param String $description 围绕着该图像形成的链接元素的 title 属性。  *  * @access public  */  function setChannelImage($url, $title, $link, $width = NULL, $height = NULL, $description = NULL) {   if (!isset($url))    $this->halt("如果你要设置图片,该图像地址属性必须填写。");   if (!isset($title))    $this->halt("如果你要设置图片,该图像描述属性必须填写。");   if (!isset($link))    $this->halt("如果你要设置图片,该图像链接属性必须填写。这个URL一般和图像地址属性相同");   $this->channel_image = "  <image>rn";   $this->channel_image .= "   <url>".$url."</url>rn";   $this->channel_image .= "   <title></title>rn";   $this->channel_image .= "   <link>".$link."rn";   //如果设置了图像宽、高则添加此属性。   if (!empty($width) && !empty($height)) {    $this->channel_image .= "   <width>".$width."</width>rn";    $this->channel_image .= "   <height>".$height."</height>rn";   }   if (!empty($description))    $this->channel_image .= "   <description></description>rn";   $this->channel_image .= "</image>rn";  }    /**//**   * 添加一条item到channel中,虽然item的子元素都是可选的,但至少要存在一个title或description  *  * @param String $title 项(item)的标题  * @param String $description 项(item)的大纲  * @param String $link 项(item)的URL  * @param String $author 项(item)作者的Email 地址  * @param String $category 包括项(item)的一个或多个分类  * @param String $comments 关于项(item)的注释页的URL  * @param String $enclosure 支持和该项(item)有关的媒体对象  * @param String $guid 唯一与该项(item)联系在一起的永久性链接  * @param String $pubDate 该项(item)是什么时候发布的  * @param String $Source 该项(item)来自哪个RSS 频道,当把项(item)聚合在一起时非常有用  *  * @access public   */  function addItem($title = NULL, $description = NULL, $link = NULL, $author = NULL, $category = NULL, $comments = NULL, $enclosure = NULL, $guid = NULL, $pubDate = NULL, $source = NULL) {   //判断是否至少添加了title或description   if (empty($title) && empty($description)) {   $this->halt("item:请至少设置title或description属性。");  }  else {    $this->item = "  <item>rn";    if (!empty($title))     $this->item .= "   <title></title>rn";    if (!empty($link))     $this->item .= "   <link>".$link."rn";    if (!empty($description))     $this->item .= "   <description></description>rn";    if (!empty($author))     $this->item .= "   <author></author>rn";    if (!empty($category))     $this->item .= "  <category></category>rn";    if (!empty($comments))     $this->item .= "   <comments></comments>rn";    if (!empty($enclosure))     $this->item .= "   <enclosure></enclosure>rn";     if (!empty($guid))     $this->item .= "   <guid>".$guid."</guid>rn";    if (!empty($pubDate))     $this->item .= "   <pubdate>".$pubDate."</pubdate>rn";    if (!empty($source))     $this->item .= "   <source></source>rn";    $this->item .= "</item>rn";   }   $this->items .= $this->item;  }   /**//**  * 输出 rss2 文档  */  function builder() {  $this->stuff();  header("Content-type:application/xml");  print $this->channel;  }  /**//**  * 兼容老版本rss生成方法,去掉了写文件功能。  *  */ function buildRssFeed($param = NULL) {  $this->builder(); } /**//**  * 合成整个RSS2文档  *  */ function stuff() {  $this->channel = $this->rss_header;  $this->channel .= $this->channel_header;  if (isset($this->channel_language))   $this->channel .= $this->channel_language;  if (isset($this->channel_copyright))   $this->channel .= $this->channel_copyright;  if (isset($this->channel_managingEditor))   $this->channel .= $this->channel_managingEditor;  if (isset($this->channel_webMaster))   $this->channel .= $this->channel_webMaster;  if (isset($this->channel_pubDate))   $this->channel .= $this->channel_pubDate;  if (isset($this->channel_lastBuildDate))   $this->channel .= $this->channel_lastBuildDate;  if (isset($this->channel_category))   $this->channel .= $this->channel_category;  if (isset($this->channel_docs))   $this->channel .= $this->channel_docs;  if (isset($this->channel_cloud))   $this->channel .= $this->channel_cloud;  if (isset($this->channel_ttl))   $this->channel .= $this->channel_ttl;  if (isset($this->channel_image))   $this->channel .= $this->channel_image;  $this->channel .= $this->channel_generator;  $this->channel .= $this->items;  $this->channel .= "</image></rss>rn"; } } /**//******************************* Rss2Gen 类使用注释 *******************/ /**//* $rss2gen = new Rss2Gen(); $rss2gen->setChannel("exblog222rss", "http://elliott.fengling.net", "elliott rss2gen"); //以下部分为可添加信息 //$rss2gen->setLanguage("zh-cn"); //$rss2gen->setCopyright("exblog @"); //$rss2gen->setManagingEditor("elliott_hee@163.com"); //$rss2gen->setWebMaster("elliott@yeah.net"); //$rss2gen->setPubDate(); //$rss2gen->setLastBuildDate(); //$rss2gen->setCategory("none"); //$rss2gen->setDocs("http://www.exblog.org/rss_docs.html"); //$rss2gen->setTtl(600); //$rss2gen->setChannelImage("/XrssFile/2006-9/24/200692413947513.gif", "demo~~ :)", "http://www.exblog.org"); //------------------------ //---添加一条记录到rss文档中,至少需要一个参数,title或description $rss2gen->addItem("item1", "item1's description", "http://www.exblog.org/?play=1",        "elliott", "默认分类", "描述呀描述。", "支持和该项(item)有关的媒体对象",       "唯一与该项(item)联系在一起的永久性链接", "2005-03-12",       "该项(item)来自哪个RSS 频道,当把项(item)聚合在一起时非常有用"); $rss2gen->addItem("item2", "item2's description"); $rss2gen->addItem("item3"); $rss2gen->builder(); //兼容老版本中方法 //$rss2gen->buildRssFeed(); */
    登入後複製


  • 本網站聲明
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智慧驅動的應用程序,用於創建逼真的裸體照片

    AI Clothes Remover

    AI Clothes Remover

    用於從照片中去除衣服的線上人工智慧工具。

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    AI Hentai Generator

    AI Hentai Generator

    免費產生 AI 無盡。

    熱門文章

    R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.最佳圖形設置
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O.如果您聽不到任何人,如何修復音頻
    3 週前 By 尊渡假赌尊渡假赌尊渡假赌
    WWE 2K25:如何解鎖Myrise中的所有內容
    4 週前 By 尊渡假赌尊渡假赌尊渡假赌

    熱工具

    記事本++7.3.1

    記事本++7.3.1

    好用且免費的程式碼編輯器

    SublimeText3漢化版

    SublimeText3漢化版

    中文版,非常好用

    禪工作室 13.0.1

    禪工作室 13.0.1

    強大的PHP整合開發環境

    Dreamweaver CS6

    Dreamweaver CS6

    視覺化網頁開發工具

    SublimeText3 Mac版

    SublimeText3 Mac版

    神級程式碼編輯軟體(SublimeText3)

    華為GT3 Pro和GT4的差異是什麼? 華為GT3 Pro和GT4的差異是什麼? Dec 29, 2023 pm 02:27 PM

    許多用戶在選擇智慧型手錶的時候都會選擇的華為的品牌,其中華為GT3pro和GT4都是非常熱門的選擇,不少用戶都很好奇華為GT3pro和GT4有什麼區別,下面就給大家介紹一下二者。華為GT3pro和GT4有什麼差別一、外觀GT4:46mm和41mm,材質是玻璃鏡板+不鏽鋼機身+高分纖維後殼。 GT3pro:46.6mm和42.9mm,材質是藍寶石玻璃鏡+鈦金屬機身/陶瓷機身+陶瓷後殼二、健康GT4:採用最新的華為Truseen5.5+演算法,結果會更加的精準。 GT3pro:多了ECG心電圖和血管及安

    修復:截圖工具在 Windows 11 中不起作用 修復:截圖工具在 Windows 11 中不起作用 Aug 24, 2023 am 09:48 AM

    為什麼截圖工具在Windows11上不起作用了解問題的根本原因有助於找到正確的解決方案。以下是截圖工具可能無法正常工作的主要原因:對焦助手已開啟:這可以防止截圖工具開啟。應用程式損壞:如果截圖工具在啟動時崩潰,則可能已損壞。過時的圖形驅動程式:不相容的驅動程式可能會幹擾截圖工具。來自其他應用程式的干擾:其他正在運行的應用程式可能與截圖工具衝突。憑證已過期:升級過程中的錯誤可能會導致此issu簡單的解決方案這些適合大多數用戶,不需要任何特殊的技術知識。 1.更新視窗與Microsoft應用程式商店應用程

    如何修復無法連線到iPhone上的App Store錯誤 如何修復無法連線到iPhone上的App Store錯誤 Jul 29, 2023 am 08:22 AM

    第1部分:初始故障排除步驟檢查蘋果的系統狀態:在深入研究複雜的解決方案之前,讓我們先從基礎知識開始。問題可能不在於您的設備;蘋果的伺服器可能會關閉。造訪Apple的系統狀態頁面,查看AppStore是否正常運作。如果有問題,您所能做的就是等待Apple修復它。檢查您的網路連接:確保您擁有穩定的網路連接,因為「無法連接到AppStore」問題有時可歸因於連接不良。嘗試在Wi-Fi和行動數據之間切換或重置網路設定(「常規」>「重置」>「重置網路設定」>設定)。更新您的iOS版本:

    php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

    php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

    Go語言中的channel是什麼意思 Go語言中的channel是什麼意思 Dec 14, 2023 pm 02:21 PM

    Go語言中的channel是一種用於協程之間進行通訊和資料同步的機制。可以被視為一種特殊的資料類型,類似於佇列或管道,用於在不同的協程之間傳遞資料。 Channel提供了兩個主要操作:發送(send)和接收(receive)。在channel中發送和接收操作都是阻塞的,這意味著如果沒有發送方或接收方準備好,操作將被阻塞,直到有一個協程準備好進行相應的操作等。

    一篇搞懂this指向,追趕70%的前端人 一篇搞懂this指向,追趕70%的前端人 Sep 06, 2022 pm 05:03 PM

    同事因為this指向的問題卡住的bug,vue2的this指向問題,使用了箭頭函數,導致拿不到對應的props。當我跟他介紹的時候他竟然不知道,隨後也刻意的看了一下前端交流群,至今最起碼還有70%以上的前端程式設計師搞不明白,今天給大家分享一下this指向,如果啥都沒學會,請給我一個大嘴巴子。

    聊聊Vue2為什麼能透過this存取各種選項中屬性 聊聊Vue2為什麼能透過this存取各種選項中屬性 Dec 08, 2022 pm 08:22 PM

    這篇文章帶大家解讀vue原始碼,來介紹一下Vue2中為什麼可以使用 this 存取各種選項中的屬性,希望對大家有幫助!

    watch4pro好還是gt好 watch4pro好還是gt好 Sep 26, 2023 pm 02:45 PM

    watch4pro和gt各自具有不使用的特點和適用場景,如果注重功能的全面性、高性能和時尚外觀,同時願意承擔較高的價格,那麼Watch 4 Pro可能更適合。如果對功能要求不高,更注重電池續航力和價格的合理性,那麼GT系列可能更適合。最終的選擇應根據個人需求、預算和喜好來決定,建議在購買前仔細考慮自己的需求,並參考各種產品的評測和比較,以做出更明智的選擇。

    See all articles