Introduction
Providing some functions for analyzing RSS document
Fegg\Tool\RSS loads an RSS 1.0 (RDF) or RSS 2.0 feed and returns its entries as arrays.
How to use
Import Fegg\Tool\RSS and create it with new, passing the feed URL.
Controller
<?php
namespace Site\Controller;
defined('FEGG_CORE_DIR') || exit;
use Fegg\Tool\RSS;
class Index extends Controller
{
public function index()
{
$rss = new RSS('https://example.com/feed');
$this->page['posts'] = $rss->fetchAll(10);
$this->displayPage('index');
}
}
Entry data
Each entry returned by RSS::fetch and RSS::fetchAll is an array with these keys.
| Key | Data type | Remarks |
|---|---|---|
| title | string | Title |
| pubDate | string | Date as written in the feed (pubDate, or dc:date for RSS 1.0) |
| datetime | DateTime | pubDate as a DateTime object |
| link | string | Link URL |
| description | string | Description (HTML entities decoded) |
| content | string | content:encoded (HTML entities decoded) |
| author | string | dc:creator |
| category | array | Category names (category, or dc:subject for RSS 1.0) |
| tag | array | Always an empty array (not implemented) |
note
- Entries whose title contains
PR:(advertisements) are skipped. - Atom feeds are not supported: no entry is returned.
- The feed is loaded with
simplexml_load_file()in the constructor. A feed that cannot be loaded is not handled, so check the URL beforehand when it may be unavailable.
Methods
RSS::__construct
Load RSS feed
RSS::fetch
Fetch the next entry of RSS feed
RSS::fetchAll
Fetch all entries or specified number of entries of RSS feed