茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    php實現(xiàn)的RSS生成類實例
    來源:易賢網(wǎng) 閱讀:946 次 日期:2015-04-28 15:33:22
    溫馨提示:易賢網(wǎng)小編為您整理了“php實現(xiàn)的RSS生成類實例”,方便廣大網(wǎng)友查閱!

    php實現(xiàn)的RSS生成類實例

    這篇文章主要介紹了php實現(xiàn)的RSS生成類,實例分析了RSS生成類的原理、定義與使用技巧,非常具有實用價值,需要的朋友可以參考下

    本文實例講述了php實現(xiàn)的RSS生成類。分享給大家供大家參考。具體如下:

    class RSS

    {

    var $title;

    var $link;

    var $description;

    var $language = "en-us";

    var $pubDate;

    var $items;

    var $tags;

    function RSS()

    {

    $this->items = array();

    $this->tags = array();

    }

    function addItem($item)

    {

    $this->items[] = $item;

    }

    function setPubDate($when)

    {

    if(strtotime($when) == false)

    $this->pubDate = date("D, d M Y H:i:s ", $when) . "GMT";

    else

    $this->pubDate = date("D, d M Y H:i:s ", strtotime($when)) . "GMT";

    }

    function getPubDate()

    {

    if(empty($this->pubDate))

    return date("D, d M Y H:i:s ") . "GMT";

    else

    return $this->pubDate;

    }

    function addTag($tag, $value)

    {

    $this->tags[$tag] = $value;

    }

    function out()

    {

    $out = $this->header();

    $out .= "<channel>\n";

    $out .= "<title>" . $this->title . "</title>\n";

    $out .= "<link>" . $this->link . "</link>\n";

    $out .= "<description>" . $this->description . "</description>\n";

    $out .= "<language>" . $this->language . "</language>\n";

    $out .= "<pubDate>" . $this->getPubDate() . "</pubDate>\n";

    foreach($this->tags as $key => $val) $out .= "<$key>$val</$key>\n";

    foreach($this->items as $item) $out .= $item->out();

    $out .= "</channel>\n";

    $out .= $this->footer();

    $out = str_replace("&", "&", $out);

    return $out;

    }

    function serve($contentType = "application/xml")

    {

    $xml = $this->out();

    header("Content-type: $contentType");

    echo $xml;

    }

    function header()

    {

    $out = '<?xml version="1.0" encoding="utf-8"?>' . "\n";

    $out .= '<rss version="2.0" xmlns:dc=" . "\n";

    return $out;

    }

    function footer()

    {

    return '</rss>';

    }

    }

    class RSSItem

    {

    var $title;

    var $link;

    var $description;

    var $pubDate;

    var $guid;

    var $tags;

    var $attachment;

    var $length;

    var $mimetype;

    function RSSItem()

    {

    $this->tags = array();

    }

    function setPubDate($when)

    {

    if(strtotime($when) == false)

    $this->pubDate = date("D, d M Y H:i:s ", $when) . "GMT";

    else

    $this->pubDate = date("D, d M Y H:i:s ", strtotime($when)) . "GMT";

    }

    function getPubDate()

    {

    if(empty($this->pubDate))

    return date("D, d M Y H:i:s ") . "GMT";

    else

    return $this->pubDate;

    }

    function addTag($tag, $value)

    {

    $this->tags[$tag] = $value;

    }

    function out()

    {

    $out .= "<item>\n";

    $out .= "<title>" . $this->title . "</title>\n";

    $out .= "<link>" . $this->link . "</link>\n";

    $out .= "<description>" . $this->description . "</description>\n";

    $out .= "<pubDate>" . $this->getPubDate() . "</pubDate>\n";

    if($this->attachment != "")

    $out .= "<enclosure url='{$this->attachment}' length='{$this->length}' type='{$this->mimetype}' />";

    if(empty($this->guid)) $this->guid = $this->link;

    $out .= "<guid>" . $this->guid . "</guid>\n";

    foreach($this->tags as $key => $val) $out .= "<$key>$val</$key\n>";

    $out .= "</item>\n";

    return $out;

    }

    function enclosure($url, $mimetype, $length)

    {

    $this->attachment = $url;

    $this->mimetype = $mimetype;

    $this->length = $length;

    }

    }

    使用示例如下:

    $feed = new RSS();

    $feed->title = "RSS Feed Title";

    $feed->link = "";

    $feed->description = "Recent articles on your website.";

    $db->query($query);

    $result = $db->result;

    while($row = mysql_fetch_array($result, MYSQL_ASSOC))

    {

    $item = new RSSItem();

    $item->title = $title;

    $item->link = $link;

    $item->setPubDate($create_date);

    $item->description = "<![CDATA[ $html ]]>";

    $feed->addItem($item);

    }

    echo $feed->serve();

    希望本文所述對大家的php程序設計有所幫助。

    更多信息請查看IT技術專欄

    更多信息請查看網(wǎng)絡編程
    易賢網(wǎng)手機網(wǎng)站地址:php實現(xiàn)的RSS生成類實例

    2026上岸·考公考編培訓報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)