2010

Jun

26

一个很好用的PHP生成RSS的类:FeedCreator
文章分类:PHP+MySQL

今天在网上闲逛,发现了一个很好用的PHP生成RSS的类:FeedCreator。尝试了一下,很不错,使用也非常简单,不多说,看实现代码:

<?php  
include("feedcreator.class.php");   
  
$rss = new UniversalFeedCreator();   
$rss->useCached(); // use cached version if age<1 hour  
$rss->title = "PHP news";   
$rss->description = "daily news from the PHP scripting world";   
  
//optional  
$rss->descriptionTruncSize = 500;  
$rss->descriptionHtmlSyndicated = true;  
  
$rss->link = "http://www.dailyphp.net/news";   
$rss->syndicationURL = "http://www.dailyphp.net/".$_SERVER["PHP_SELF"];   
  
$image = new FeedImage();   
$image->title = "dailyphp.net logo";   
$image->url = "http://www.dailyphp.net/images/logo.gif";   
$image->link = "http://www.dailyphp.net";   
$image->description = "Feed provided by dailyphp.net. Click to visit.";   
  
//optional  
$image->descriptionTruncSize = 500;  
$image->descriptionHtmlSyndicated = true;  
  
$rss->image = $image;   
  
// get your news items from somewhere, e.g. your database:   
mysql_select_db($dbHost, $dbUser, $dbPass);   
$res = mysql_query("SELECT * FROM news ORDER BY newsdate DESC");   
while ($data = mysql_fetch_object($res)) {   
    $item = new FeedItem();   
    $item->title = $data->title;   
    $item->link = $data->url;   
    $item->description = $data->short;   
      
    //optional  
    $item->descriptionTruncSize = 500;  
    $item->descriptionHtmlSyndicated = true;  
  
    $item->date = $data->newsdate;   
    $item->source = "http://www.dailyphp.net";   
    $item->author = "John Doe";   
?>  
       
    $rss->addItem($item);   
}

点击此处下载feedcreator.class.php

注:(1)、该类默认时区为+01:00,如需修改请修改feedcreator.class.php第159行;
(2)该类默认编码为ISO-8859-1,如需修改请修改feedcreator.class.php第159行。

本站原创,转载请标明:来自追梦博客(http://www.wuleilei.com/)

本文地址:http://www.wuleilei.com/Blog/240

相关文章

PHP经典乱码“锘”字与解决办法 (2009-06-08)

用include函数后出现乱码的方法 (2009-06-09)

PHP下载CSS文件中的图片 (2009-06-16)

php 伪静态 (url rewrite mod_rewrite 重写) (2009-07-28)

用thinkphp重新把博客写一遍 (2009-08-02)

PHP中StripSlashes函数的使用 (2009-09-16)

一段php加密/解密代码(解决密匙中含有加号) (2009-11-07)

php换行转换函数nl2br() (2009-11-09)

PHP100视频教程全集下载(含解压密码) (2010-09-17)

Mac OS X 中配置PHP的MCrypt扩展 (2011-12-08)

看看他们的脚印

闲言碎语

晚上和爸妈吃个饭。 (2月6日)

装修好累哟 (2月4日)

《斯巴达克斯:复仇》 (2月3日)

文章分类

最近文章

iOS开发之回调delegate的方法...

iOS开发之使用AES加密(兼容Obj...

事情好多哦

iOS开发之获取本机IP地址的方法

简单记录PC上安装苹果系统

最近评论

日志归档

友情链接

其它功能

随机标签