joelwmale / rss-feed-php
RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.
1.1.0
2018-12-28 10:20 UTC
Requires
- php: ^7.1
- ext-simplexml: *
- nesbot/carbon: ^1.26.3
Requires (Dev)
- phpstan/phpstan: ^0.11.0@dev
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-10-29 00:16:44 UTC
README
RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.
It requires PHP 7.1 or newer with cURL installed on the system, and is licensed under the MIT License.
Installation
Composer:
composer require joelwmale/rss-feed-php
Usage
Download RSS feed from URL:
use joelwmale\RSSFeedPHP; $feed = RSSFeedPHP::load($url);
Elements are returned as SimpleXMLElement
objects, with the outter most object being an std::class.
echo 'Title: ', $feed->title; echo 'Description: ', $feed->description; echo 'Link: ', $feed->link; foreach ($feed->item as $item) { echo 'Title: ', $item->title; echo 'Link: ', $item->link; echo 'Date: ', $item->date; echo 'Description ', $item->description; echo 'HTML encoded content: ', $item->{'content:encoded'}; }
A helper class is available if you wish to convert it to an array instead:
use joelwmale\RSSFeedPHP; $feed = RSSFeedPHP::load($url); $feed->toArray();
Caching is available by adding the following:
use joelwmale\RSSFeedPHP; RSSFeedPHP::$cacheDir = __DIR__ . '/tmp'; RSSFeedPHP::$cacheExpire = '5 hours';
Testing
Tests are run via phpunit:
phpunit