php 生成RSS文件类实例代码


本文摘自PHP中文网,作者怪我咯,侵删。

RSS(简易信息聚合):是一种消息来源格式规范,用以发布经常更新数据的网站,例如博客文章、新闻、音频或视频的网摘。RSS文件(或称做摘要、网络摘要、或频更新,提供到频道)包含了全文或是节录的文字,再加上发用者所订阅之网摘布数据和授权的元数据。网络摘要能够使发行者自动地发布他们的数据,同时也使读者能更够定期更新他们喜欢的网站或是聚合不同网站的网摘。RSS摘要可以借由RSS阅读器、feed reader或是aggregator等网页或以桌面为架构的软件来阅读。标准的XML档式可允许信息在一次发布后通过不同的程序阅览。用户借由将网摘输入RSS阅读器或是用鼠标点取浏览器上指向订阅程序的RSS小图标之URI(非通常称为URL)来订阅网摘。RSS阅读器定期检阅是否有更新,然后下载给监看用户界面。

RSS可以是以下三种解释中任一种的缩写,但其实这三者都是指同一种联合供稿(Syndication)的技术:

这篇文章主要介绍了PHP生成RSS文件类,可实现PHP生成RSS文件的功能,对于网站建设与优化来说具有一定的实用价值,需要的朋友可以参考下

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

代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

<?php

if (defined('_class_rss_php')) return;

define('_class_rss_php教程',1);

 

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, $link, $description ,$pubdate) {

       $this->items[] = array('titile' => $title ,

                        'link' => $link,

                        'description' => $description,

                        'pubdate' => $pubdate);

   }

  

   function buildrss() {

       $s = "<!--l version="1.0" encoding="gb2312"--> ";

       // start channel

       $s .= " ";

       $s .= " "

       $s .= "<link />{$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 .= "<link />{$this->items[$i]['link']} ";

           $s .= "<!--data[{$thi-->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 生成RSS文件类实例代码的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

详细介绍消息队列的概念、原理及使用场景(附案例)

PHP中获取系统信息的方法

介绍sql server临时表和游标实例用法

介绍PHP + mysql 实现数据分页显示

docker安装mysql的简单实例

PHP 处理数组和xml之间的互相转换实例代码

PHPstorm如何通过ssh连接mysql数据库

解决PHPmyadmin网页打不开问题

PHP中数据库的查询方法应该如何实现?

安装redis及PHP的redis扩展

更多相关阅读请进入《PHP》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...