lastRSS的使用

lastRSS 是小巧高效的php处理rss开源类。百度一下,国内有不少使用者,但中文资料几乎没有。其实包括注释才220行的代码也不需要太多的资料,下面的一段代码,应该足够说明问题了。

<?php

/**
* @author citywill (http://blog.citywill.net)
* @copyright 2008
*/

$rssURL=’http://blog.citywill.net/feed’;    //指定RSS源

include(’lastRSS.php’);        //载入类
$rss=new lastRSS;            //实例化

$rss->cache_dir=’cache’;    //设置缓存目录,要手动建立
$rss->cache_time=3600;    //设置缓存时间。默认为0,即随访问更新缓存;建议设置为3600,一个小时
$rss->default_cp=’UTF-8′;    //设置字符编码,默认为UTF-8
$rss->items_limit=10;        //设置输出数量,默认为10
$rss->date_format=’U';        //设置时间格式。默认为字符串;U为时间戳,可以用date设置格式
$rss->stripHTML=false;        //设置过滤html脚本。默认为false,即不过滤
$rss->CDATA=’content’;        //设置处理CDATA信息。默认为nochange。另有strip和content两个选项

$rs=$rss->Get($rssURL);        //处理RSS并获取内容
//print_r($rs);                //输出

echo ‘
<h1><a href=”‘.$rs[’link’].’”>’.$rs[’title’].’</a> <a href=”‘.$rssURL.’”>feed</a></h1>
<div class=”desc”>’.$rs[’description’].’</div>’;

echo ‘<ul>’;
foreach($rs[’items’] as $rsItem)
{
echo ‘
<li>
<h2>
[’.date(’m-j’,$rsItem[pubDate]).’]
<a href=”‘.$rsItem[’link’].’”>’.$rsItem[’title’].’</a>
</h2>
<div class=”desc”>’.substr($rsItem[’description’],0,500).’</div>
</li>’;
}
echo ‘</ul>’;
?>

到这里下载lastRSS

阅读(464 次)

Post a Comment
*Required
*Required (Never published)