加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP生成RSS文件类实例

发布时间:2020-12-12 20:33:06 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解PHP生成RSS文件类文件。供大家参考研究。具体如下: PHP RSS 生成类实例代码如下: 代码如下: 使用说明: $rss = new rss('redfox','http://jb51.cc/',"redfox's blog"); $rss-additem('rss class',"//www.jb51.cc","xxx",date()); $rss-

本篇章节讲解PHP生成RSS文件类文件。分享给大家供大家参考。具体如下:

PHP RSS 生成类实例代码如下:

代码如下:
  • 使用说明:
  • $rss = new rss('redfox','http://52php.cn/',"redfox's blog");
  • $rss->additem('rss class',"//www.52php.cn","xxx",date());
  • $rss->additem(...);
  • $rss->savetofile(...);
    */
  • 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,$description,$pubdate) {
    $this->items[] = array('titile' => $title,
    'link' => $link,
    'description' => $description,
    'pubdate' => $pubdate);
    }

    function buildrss() {
    $s = " ";
    // start channel
    $s .= " ";
    $s .= " "
    $s .= "{$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 .= "{$this->items[$i]['link']} ";
    $s .= "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);
    }
    }
    ?>

    希望本文所述对大家的PHP程序设计有所帮助。

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读