michaelhall/rss-feed

Simple RSS feed creator for PHP

v2.1.0 2018-01-12 18:11 UTC

This package is auto-updated.

Last update: 2020-03-23 00:33:49 UTC


README

Build Status codecov.io Maintainability StyleCI License Latest Stable Version Total Downloads

Simple RSS feed creator.

Requirements

  • PHP >= 7.1

Install with composer

$ composer require michaelhall/rss-feed

Basic usage

<?php

require __DIR__ . '/vendor/autoload.php';

// Create the feed.
$feed = new \MichaelHall\RssFeed\RssFeed(
    'Feed Title', 
    \DataTypes\Url::parse('https://example.com/'),
    'The feed description.'
);

// This is optional but recommended by W3C feed validator.
$feed->setFeedUrl(\DataTypes\Url::parse('https://example.com/path/to/feed'));

// Add an item.
$feedItem = new \MichaelHall\RssFeed\RssItem(
   'Item Title',
   \DataTypes\Url::parse('https://example.com/path/to/item-page'),
   'The item description',
   new \DateTimeImmutable('2017-08-22 19:56:00')
);

$feed->addItem($feedItem);

// Prints the RSS feed.
echo $feed;

Add an image to the feed

$feedImage = new RssImage(
   \DataTypes\Url::parse('https://example.com/path/to/image'),
   'Image Title',
   \DataTypes\Url::parse('https://example.com/')
);

$feed->setImage($feedImage);

License

MIT