vinelab / rss
An elegant RSS 2.0 and Atom client.
Installs: 42 860
Dependents: 2
Suggesters: 0
Security: 0
Stars: 48
Watchers: 6
Forks: 17
Open Issues: 1
Requires
- php: >=7.1
- ext-simplexml: *
- illuminate/support: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0
- vinelab/http: *
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 7.*.*|8.*|9.*
README
RSS Client
A simple and radical RSS client that supports RSS 0.92, 2.0 and Atom feeds.
Synopsis
Fetch Feeds
$rss->feed('https://stackoverflow.com/feeds/tag?tagnames=php&sort=newest');
Parse Feeds
$feed->info(); $feed->articles();
Installation
composer require vinelab/rss
Laravel Setup
Edit app.php and add 'Vinelab\Rss\RssServiceProvider',
to the 'providers'
array.
It will automatically alias itself as RSS so no need to aslias it in your app.php unless you would like to customize it. In that case edit your 'aliases' in app.php adding 'MyRSS' => 'Vinelab\Rss\Facades\RSS',
Usage
Fetch an RSS feed
require 'vendor/autoload.php'; use Vinelab\Rss\Rss; $rss = new Rss(); $feed = $rss->feed('https://stackoverflow.com/feeds/tag?tagnames=php&sort=newest'); // $feed is now an instance of Vinelab\Rss\Feed $info = $feed->info(); $count = $feed->articlesCount(); $articles = $feed->articles();
Feed Info
$info = $feed->info(); echo json_encode($info);
{ "title": "Newest questions tagged php - Stack Overflow", "subtitle": "most recent 30 from stackoverflow.com", "updated": "2020-07-16T19:14:29Z", "id": "https://stackoverflow.com/feeds/tag?tagnames=php&sort=newest" }
Feed Articles
Accessing Articles
$articles = $feed->articles();
This will give you an instance of Vinelab\Rss\ArticlesCollection
which is
an extension of Illuminate\Support\Collection.
Each item of this collection is an instance of Vinelab\Rss\Article
from which you can safely access any of the properties in the entry.
Article
Is an object which properties are dynamically accessed such as $article->title
.
Whichever fields exist in the feed's entry will be accessible as read-only
property, making Article
an immutable object.
You may also call isset($article->someField)
to check whether the field exists for a designated entry.
$article = $articles->first(); echo $article->title; // ABBA piano seen raising money, money, money at auction echo $article->whatever; // null
Or iterate through the articles
foreach ($feed->articles() as $article) { $title = $article->title; }
You may also access the article's original XML format with
$article->xml();
Got Questions?
Reach out in the issues.