It’s very easy to fetch RSS feeds with PHP and use them on your website, if you wish. This could be useful to aggregate information or news from relevant sources, or if you for some other reason need to import or display data which you have available as a feed, SimplePie is a PHP library which provides this support through an easy framework which allows you to extract data in an object oriented way. Nice and easy.
Example how to start SimplePie and fetch a feed
// Instantiate SimplePie $feed = new SimplePie(); // Define which URL to load the feed from $feed->set_feed_url('https://simplepie.org/blog/feed/'); // Initialize the feed $feed->init();
Use information from the feed
// You can get various meta data from the feed echo $feed->get_permalink(); echo $feed->get_title(); echo $feed->get_description();
Use feed items
// Go through each item and display information for them foreach ($feed->get_items() as $item) {
echo $item->get_title(); echo $item->get_permalink(); echo $item->get_description(); echo $item->get_date('j F Y | g:i a');
}
This should get you started to use feeds in your project :-)
No comments yet (leave a comment)