RSS Generator

RSS Generator

Simplest RSS Generator for PHP.

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 License Support
Source Packagist Version Packagist Downloads

Install

RSS Generator requires the XMLWriter libxml extension from PHP.

Install the latest version using Composer

composer require pharaonic/php-rss
Usage

Channel Creation

Create a new channel with setting some required/optional elements.

use Pharaonic\RSS\RSS;

$feed = (new RSS())
    ->setTitle('PAGE TITLE')                // REQUIRED
    ->setDescription('PAGE DESCRIPTION')    // REQUIRED
    ->setLink('https://pharaonic.io')       // REQUIRED

    ->setImage('https://pharaonic.io/images/logo.png')  // OPTIONAL
    ->setLanguage('en')                                 // OPTIONAL
    ->setCopyright('Copyright 2021, Pharaonic')         // OPTIONAL
    ->setPublished('Fri, 02 Oct 2020 00:00:01 +0200')   // OPTIONAL
    ->setUpdated('Tue, 15 Jun 2021 15:00:00 +0200');    // OPTIONAL

Item Creation

Create a new item with setting some required/optional elements.

use Pharaonic\RSS\RSSItem;

$item = (new RSSItem)
    ->setTitle('Hijri')                                 // REQUIRED
    ->setDescription('Hijri DateTime (Islamic).')       // REQUIRED
    ->setLink('https://pharaonic.io/package/1-general-php/7-hijri')     // REQUIRED

    ->setGUID('https://pharaonic.io/package/1-general-php/7-hijri')     // OPTIONAL
    ->setCategory('Packages')->setCategory('General PHP')               // OPTIONAL
    ->setAuthor('someone@example.com (Someone Name)')                   // OPTIONAL
    ->setPublished('Tue, 25 May 2021 16:14:00 +0200');                  // OPTIONAL

Item Appending

Appending an item to a channel.

$feed->setItem($item);
            
// OR
$item->appendToChannel($feed);

Display & Render

Displaying and Rendering the feed.

// Display the feed with Content-Type=text/xml
echo $feed->render();

// Just Display the feed as string
echo $feed;