问题
Are there any free php/javascript libraries out there which would help in displaying an RSS feed as html?
回答1:
In my Opinion Simplepie is one of the Best RSS parsers.
Here is an example:
require_once('simplepie.inc');
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->init();
$feed->handle_content_type();
<?php foreach ($feed->get_items(0, 5) as $item): ?>
<div class="item">
<h2 class="title"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
<?php echo $item->get_description(); ?>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>
回答2:
Maybe SimplePie might help, here -- quoting its FAQ, it's :
- A code library, written in PHP, intended to make it ridiculously easy for people to manage RSS and Atom feeds.
- An easy to use API that handles all of the dirty work when it comes to fetching, caching, parsing, normalizing data structures between RSS and Atom formats, handling character encoding translation, and sanitizing the resulting data.
Of couse, it will not do everything for you -- but it might help you get started.
Other solutions include, for instance, Zend_Feed_Reader or MagpieRSS.
回答3:
Try Magpie RSS. It can parse RSS feeds to arrays which you can easily iterate through and build your HTML.
回答4:
It's not actually a library either, but I would definitely recommand you to use XSL/XSLT.
来源:https://stackoverflow.com/questions/2037351/output-rss-feed-as-html