Skip to main content
Version: Fegg 5.x

RSS::__construct

Load a feed

Description​

public RSS::__construct( string $url, [ array $options = array() ] )

Loads and parses an RSS 1.0, RSS 2.0 or Atom feed. The entries can then be read with RSS::fetch or RSS::fetchAll.

An http:// or https:// URL is fetched with Fegg\Http\Client; any other value is read as a local file.

Throws a \RuntimeException when:

  • the URL cannot be fetched (connection error, timeout, or an HTTP status other than 200);
  • the file does not exist or cannot be read;
  • the document is not XML, or is not an RSS or Atom feed.

Arguments​

NameData typeDefaultRemarks
$urlstringFeed URL, or the path of a file
$optionsarrayarray()Options (see below)
KeyData typeDefaultRemarks
skip_prbooleanfalsetrue: leave out the posts whose title contains PR: (advertisements of some blog services)
timeoutint10Seconds for the whole request (the connection: 3 seconds)

Example​

Controller
use Fegg\Tool\RSS;

try {
$rss = new RSS('https://example.com/feed', array('skip_pr' => true, 'timeout' => 5));
} catch (\RuntimeException $e) {
// cannot be fetched, or not a feed: $e->getMessage()
}

// A local file
$rss = new RSS(FEGG_SITE_DIR . '/data/feed.xml');