PHP code example of rwslinkman / simple-rss-feed-renderer

1. Go to this page and download the library: Download rwslinkman/simple-rss-feed-renderer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rwslinkman / simple-rss-feed-renderer example snippets


// Article content loaded in a way preferred by you
$articlesList = array(...);

$feedBuilder = (new FeedBuilder())
    ->withChannelTitle("Fun facts")
    ->withChannelDescription("Daily fun facts for you to read")
    ->withChannelUrl("https://funfacts.nl/articles");

foreach ($articlesList as $article) {
    $feedBuilder
        ->addItem()
        ->withTitle($article->getTitle())
        ->withDescription($article->getSubtitle())
        ->withLink("https://funfacts.nl/articles/" . $article->getId())
        ->withPubDate($article->getCreatedAt())
        ->buildItem();
}
$rssFeed = $feedBuilder->build();

// Don't forget to set "application/rss+xml" for the "Content-Type" header
$renderer = new SimpleRssFeedRenderer();
$renderer->configurePrettyPrint(true);
$renderer->configureValidateBeforeRender(true);
$rssXml = $renderer->render($rssFeed);

$feedBuilder = (new FeedBuilder())
    ->withChannelTitle("Fun facts")
    ->withChannelDescription("Daily fun facts for you to read")
    ->withChannelUrl("https://funfacts.nl/articles");
$rssFeed = $feedBuilder->build();

// it will throw InvalidRssException containing the ValdationReport in case of errors
$validator = new RssValidator();
$validator->validate($rssFeed);