MagpieRSS是a simple RSS integration tool

环境要求:

PHP 4+ with xml (expat) support.
Optionally:
* PHP5 with libxml2 support.
* cURL for SSL support
* iconv (preferred) or mb_string for expanded character set support

安装:

复制 以下4个文件和一个文件夹(rss_fetch.inc, rss_parser.inc, rss_cache.inc, rss_utils.inc, and extlib) 到目录magpierss,将这个magpierss目录放到你的php include 路径里 现在你可以在一个php文件里这样调用maspie:
require_once(‘magpierss/rss_fetch.inc’);
可以这样寻找你的PHP include path,新建一个phpinfo.php文件,内容为:
<?php phpinfo(); ?>

将这个文件放到Web服务器目录下,从浏览器打开,然后查找include_path即可

简单使用:

1.由于RSS默认包含15条 如果想显示少一些条目,可以这么做:
$num_items = 10;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
2. 显示比某日期更新的标题

require_once('rss_utils.inc');
# get all headlines published today
$today = getdate();
# today, 12AM
$date = mktime(0,0,0,$today['mon'], $today['mday'], $today['year']);
$rss = fetch_rss($url);
foreach ( $rss->items as $item ) {
   $published = parse_w3cdtf($item['dc']['date']);
   if ( $published >= $date ) {
        echo "Title: " . $item['title'];
        echo "Published: " . date("h:i:s A", $published);
        echo "<p>";
    }
}


3.如果rss源里包含中文,会出现乱码,可以通过指定具体字符编码集的方式来解决,具体方法如下:

编辑rss_fetch.inc,在开头添加以下两行:

define(‘MAGPIE_OUTPUT_ENCODING’,’UTF-8′);

define(‘MAGPIE_INPUT_ENCODING’,’UTF-8′);