メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

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.

KeyData typeRemarks
titlestringTitle
pubDatestringDate as written in the feed (pubDate, or dc:date for RSS 1.0)
datetimeDateTimepubDate as a DateTime object
linkstringLink URL
descriptionstringDescription (HTML entities decoded)
contentstringcontent:encoded (HTML entities decoded)
authorstringdc:creator
categoryarrayCategory names (category, or dc:subject for RSS 1.0)
tagarrayAlways an empty array (not implemented)
メモ
  • 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​