michaelhall/rss-feed

Simple RSS feed creator for PHP

v3.0.0 2022-09-19 16:00 UTC

This package is auto-updated.

Last update: 2024-04-19 19:54:09 UTC


README

Tests StyleCI License Latest Stable Version Total Downloads

Simple RSS feed creator.

Requirements

  • PHP >= 8.0

Install with composer

$ composer require michaelhall/rss-feed

Basic usage

<?php

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

use DataTypes\Net\Url;
use MichaelHall\RssFeed\RssFeed;
use MichaelHall\RssFeed\RssItem;

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

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

// Add an item.
$feedItem = new RssItem(
    'Item Title',
    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

use MichaelHall\RssFeed\RssImage;

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

$feed->setImage($feedImage);

License

MIT