vinelab/rss

An elegant RSS 2.0 and Atom client.

v2.0.3 2022-03-07 15:50 UTC

This package is auto-updated.

Last update: 2024-04-07 20:21:20 UTC


README

Build Status

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.

MIT LICENSE