, (*1)
A simple and radical RSS client that supports RSS 0.92, 2.0 and Atom feeds., (*2)
Synopsis
Fetch Feeds, (*3)
$rss->feed('https://stackoverflow.com/feeds/tag?tagnames=php&sort=newest');
Parse Feeds, (*4)
$feed->info();
$feed->articles();
Installation
composer require vinelab/rss
, (*5)
Laravel Setup
Edit app.php and add 'Vinelab\Rss\RssServiceProvider',
to the 'providers'
array., (*6)
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',
, (*7)
Usage
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, (*8)
$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., (*9)
Article, (*10)
Is an object which properties are dynamically accessed such as $article->title
., (*11)
Whichever fields exist in the feed's entry will be accessible as read-only
property, making Article
an immutable object., (*12)
You may also call isset($article->someField)
to check whether the field exists for a designated entry., (*13)
$article = $articles->first();
echo $article->title; // ABBA piano seen raising money, money, money at auction
echo $article->whatever; // null
Or iterate through the articles, (*14)
foreach ($feed->articles() as $article) {
$title = $article->title;
}
You may also access the article's original XML format with, (*15)
$article->xml();
Got Questions?
Reach out in the issues., (*16)
MIT LICENSE, (*17)