PHP code example of shevabam / rss-feed-maker
1. Go to this page and download the library: Download shevabam/rss-feed-maker 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/ */
shevabam / rss-feed-maker example snippets
$feed = new \RssFeedMaker\Feed;
$feed
->setTitle('RSS Feed Title')
->setDescription('Recent articles on my website')
->setLink('https://website.com')
->setCopyright('MyWebsite.com')
->setLanguage('en')
->setImage([
'title' => 'Image title',
'url' => 'https://website.com/Image.jpg',
'link' => 'https://website.com',
])
;
$feed->setEncoding('iso-8859-1');
$posts = [
[
'title' => 'Post title #1',
'link' => 'https://website.com/1-post-title',
'published_at' => '2023-03-18 12:00:00',
'description' => 'Blog post about something very important',
],
[
'title' => 'Post title #2',
'link' => 'https://website.com/2-post-title',
'published_at' => '2023-03-11 16:30:00',
'description' => 'Blog post about something very important',
],
];
foreach ($posts as $post)
{
$item = new \RssFeedMaker\Item;
$item
->setTitle($post['title'])
->setLink($post['link'])
->setDescription($post['description'])
->setPubDate($post['published_at'])
;
$feed->addItem($item);
}
echo $feed->generate();
$feed->save('path/to/the/feed.xml');
$feed = new \RssFeedMaker\Feed;
$feed
->setTitle('RSS Feed Title')
->setDescription('Recent articles on your website')
->setLink('https://website.com')
->setCopyright('MyWebsite.com')
->setImage([
'title' => 'Image title',
'url' => 'https://website.com/Image.jpg',
'link' => 'https://website.com',
])
;
$posts = [
[
'title' => 'Post title #1',
'link' => 'https://website.com/1-post-title',
'published_at' => '2023-03-14 12:00:00',
'author' => 'John Doe',
'description' => 'Blog post about something very important',
],
[
'title' => 'Post title #2',
'link' => 'https://website.com/2-post-title',
'published_at' => '2023-03-08 16:30:00',
'author' => 'Jane Doe',
'description' => 'Blog post number two',
],
[
'title' => 'Post title #3',
'link' => 'https://website.com/3-post-title',
'published_at' => '2023-03-01 08:45:00',
'enclosure' => [
'url' => 'https://website.com/podcasts/example.mp3',
'length' => 12345,
'type' => 'audio/mpeg',
],
],
];
foreach ($posts as $post)
{
$item = new \RssFeedMaker\Item;
$item->setTitle($post['title']);
$item->setLink($post['link']);
$item->setDescription(isset($post['description']) ? $post['description'] : '');
$item->setPubDate(isset($post['published_at']) ? $post['published_at'] : '');
$item->setAuthor(isset($post['author']) ? $post['author'] : '');
$item->setCategory(isset($post['category']) ? $post['category'] : '');
$item->setGuid(isset($post['guid']) ? $post['guid'] : '');
$item->setSource(isset($post['source']) ? $post['source'] : []);
$item->setEnclosure(isset($post['enclosure']) ? $post['enclosure'] : []);
$feed->addItem($item);
}
$feed->save('public/feed.xml');