dansup/rss-php

This package is abandoned and no longer maintained. No replacement package was suggested.

RSS & Atom Feeds for PHP is a very small and easy-to-use library for consuming an RSS and Atom feed

1.3.0 2017-09-17 03:34 UTC

This package is auto-updated.

Last update: 2020-02-23 04:14:54 UTC


README

Downloads this Month Latest Stable Version License

RSS & Atom Feeds for PHP is a very small and easy-to-use library for consuming an RSS and Atom feeds. This project is a forked of David Grudl's rs-php https://github.com/dg/rss-php

It requires PHP 5.5 and Guzzle 6.1 and is licensed under the New BSD License. You can obtain the latest version from our GitHub repository or install it via Composer:

php composer.phar require dansup/rss-php

Usage

Download RSS feed from URL:

$rss = Feed::loadRss($url);

The returned properties are SimpleXMLElement objects. Extracting the information from the channel is easy:

echo 'Title: ', $rss->title;
echo 'Description: ', $rss->description;
echo 'Link: ', $rss->link;

foreach ($rss->item as $item) {
	echo 'Title: ', $item->title;
	echo 'Link: ', $item->link;
	echo 'Timestamp: ', $item->timestamp;
	echo 'Description ', $item->description;
	echo 'HTML encoded content: ', $item->{'content:encoded'};
}

Download Atom feed from URL:

$atom = Feed::loadAtom($url);

You can set your own Guzzle instance to the static client property

Feed::$client = new GuzzleHttp\Client(['headers' => ['User-Agent' => 'FeedPHP/1.0']]);

and it will be reused.

You can pass Guzzle request options (including auth user/password) on each call

$atom = Feed::loadAtom($url, ['auth' => ['peter', 'secret']);

You can also enable caching using https://github.com/Kevinrob/guzzle-cache-middleware

//  Simple volatile memory cache example check docs for more options 
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Kevinrob\GuzzleCache\CacheMiddleware;

// Create default HandlerStack
$stack = HandlerStack::create();

// Add this middleware to the top with `push`
$stack->push(new CacheMiddleware(), 'cache');

// Initialize the client with the handler option
Feed::$client = new Client(['handler' => $stack]);

(c) David Grudl, 2008 (http://davidgrudl.com) (c) grunjol, 2017 (https://github.com/grunjol) (c) dansup, 2017 (https://github.com/dansup)