### Generate RSS Feed with PHP
Source: https://github.com/aherne/rss-generator/blob/master/README.md
A simple example demonstrating how to create a basic RSS feed using the API. Instantiate Channel and Item objects, then pass the Channel to the RSS constructor. The feed is displayed by echoing the RSS object.
```php
$channel = new \Lucinda\RSS\Channel("Lucinda Framework", "https://www.lucinda-framework.com", "Current headlines from Lucinda Framework");
$channel->addItem(new \Lucinda\RSS\Item("STDOUT MVC API", "STDOUT MVC API was upgraded to a new version"));
$channel->addItem(new \Lucinda\RSS\Item("STDERR MVC API", "STDERR MVC API was upgraded to a new version"));
$rss = new \Lucinda\RSS\RSS($channel);
echo $rss; // displays RSS feed
```
--------------------------------
### Update Composer and Run Tests
Source: https://github.com/aherne/rss-generator/blob/master/README.md
Commands to update project dependencies using Composer and run the unit tests for the RSS generator API. Ensure PHP 8.1+ is installed.
```console
composer update
```
```console
php test.php
```
--------------------------------
### Create and Configure an RSS Feed Item
Source: https://context7.com/aherne/rss-generator/llms.txt
Use this snippet to create a new RSS feed item with a title and description. Optional fields like link, author, category, comments, GUID, publication date, source, and media enclosures can be set.
```php
Named arguments improve code readability.
" // HTML is CDATA-escaped
);
$item->setLink("https://techblog.example.com/php-83-named-args");
$item->setAuthor("jane@techblog.example.com");
$item->setCategory("PHP");
$item->setComments("https://techblog.example.com/php-83-named-args#comments");
$item->setGuid("https://techblog.example.com/php-83-named-args");
$item->setPubDate(strtotime("2024-05-20")); // converted to RFC-822
$item->setSource("https://php.net/feed");
// Attach a podcast/media enclosure
$item->setEnclosure(new Enclosure(
"https://techblog.example.com/audio/ep42.mp3",
20480000, // byte size
"audio/mpeg" // MIME type
));
echo $item;
/*
PHP 8.3 Named ArgumentsNamed arguments improve code readability.]]>
https://techblog.example.com/php-83-named-args
jane@techblog.example.com
...
*/
} catch (Exception $e) {
echo "Item error: " . $e->getMessage();
}
```
--------------------------------
### Channel Constructor
Source: https://github.com/aherne/rss-generator/blob/master/README.md
Initializes a new Channel object with the required title, link, and description.
```APIDOC
## Channel Constructor
### Description
Initializes a new Channel object with the required title, link, and description. The description is automatically escaped using CDATA.
### Method
__construct
### Parameters
#### Path Parameters
- **title** (string) - Required - The title of the channel.
- **link** (string) - Required - The URL of the channel.
- **description** (string) - Required - The description of the channel.
### Response
#### Success Response (void)
This method does not return a value.
```
--------------------------------
### Generate RSS Feed with Custom Namespace
Source: https://context7.com/aherne/rss-generator/llms.txt
Demonstrates creating a basic RSS feed using the RSS and Channel classes. Includes registering a custom XML namespace (dc) and outputting the complete XML document. Ensure the vendor/autoload.php is included and exceptions are handled.
```PHP
addItem(new Item("Release 3.0", "Version 3.0 is now available."));
$rss = new RSS($channel);
// Register a custom namespace (e.g., Dublin Core)
$rss->addNamespace("dc", "http://purl.org/dc/elements/1.1/");
// Output the full XML document
header("Content-Type: application/rss+xml; charset=UTF-8");
echo $rss;
/*
Lucinda Framework
https://www.lucinda-framework.com
Release 3.0
*/
} catch (Exception $e) {
// Thrown when addNamespace receives an invalid URL
echo "Error: " . $e->getMessage();
}
```
--------------------------------
### Configure Channel Metadata and Sub-Objects
Source: https://context7.com/aherne/rss-generator/llms.txt
Shows how to set various metadata for an RSS channel, including language, copyright, dates, and categories. It also demonstrates attaching optional sub-objects like Image, Cloud, SkipHours, and SkipDays. Ensure all required imports are present and exceptions are handled.
```PHP
setLanguage("en-us");
$channel->setCopyright("2024 Tech Blog");
$channel->setManagingEditor("editor@techblog.example.com");
$channel->setWebMaster("webmaster@techblog.example.com");
$channel->setPubDate(strtotime("2024-06-01")); // converted to RFC-822
$channel->setLastBuildDate(strtotime("2024-06-15"));
$channel->setCategory("Technology");
$channel->setGenerator("Lucinda RSS Library");
$channel->setDocs("https://www.rssboard.org/rss-specification");
$channel->setTtl(60); // cache for 60 minutes
// Attach optional sub-objects
$channel->setImage(new Image(
"https://techblog.example.com/logo.png",
"Tech Blog Logo",
"https://techblog.example.com"
));
$channel->setCloud(new Cloud(
"rpc.techblog.example.com", 80, "/rpc", "pingMe", "soap"
));
$channel->setSkipHours(new SkipHours([0, 1, 2, 3, 4, 5])); // skip midnight–5 AM
$channel->setSkipDays(new SkipDays(["Saturday", "Sunday"]));
$channel->addItem(new Item("Hello World", "Our first post!"));
$channel->addItem(new Item("PHP 8.3 Features", "A deep dive into PHP 8.3."));
echo $channel;
} catch (Exception $e) {
echo "Channel error: " . $e->getMessage();
}
```
--------------------------------
### Attach a Media Enclosure to an Item
Source: https://context7.com/aherne/rss-generator/llms.txt
Use the Enclosure class to attach media files like audio or video to an RSS item. Provide the media URL, exact byte size, and MIME type.
```php
} catch (Exception $e) {
echo "Enclosure error: " . $e->getMessage();
}
```
--------------------------------
### Enclosure — Media Attachment
Source: https://context7.com/aherne/rss-generator/llms.txt
Attaches a media object to an Item, enabling podcast-style feeds. URL, byte length, and MIME type are required.
```APIDOC
## Enclosure — Media Attachment
`Enclosure` attaches a media object (audio, video, image) to an `Item`, enabling podcast-style feeds. URL, byte length, and MIME type are all required.
```php
} catch (Exception $e) {
echo "Enclosure error: " . $e->getMessage();
}
```
```
--------------------------------
### Create a Channel Logo Image
Source: https://context7.com/aherne/rss-generator/llms.txt
Configure an optional logo for your RSS channel using the Image class. Set the image URL, alt text, click-through link, and optionally dimensions and a description.
```php
setWidth(144);
$image->setHeight(144);
$image->setDescription("The official Tech Blog logo");
echo $image;
/*
https://techblog.example.com/logo.pngTech Blog
https://techblog.example.com
144144
*/
} catch (Exception $e) {
echo "Image error: " . $e->getMessage();
}
```
--------------------------------
### Register a Real-Time Update Notification Service
Source: https://context7.com/aherne/rss-generator/llms.txt
Configure a Cloud object to notify subscribers of feed updates via a web service. Specify the service's domain, port, path, registration procedure, and protocol.
```php
} catch (Exception $e) {
echo "Cloud error: " . $e->getMessage();
}
```
--------------------------------
### Create a Search Input Box for the Channel
Source: https://context7.com/aherne/rss-generator/llms.txt
Implement a TextInput object to add a search box to your RSS feed. Define the input field name, submit button label, form action URL, and a description for the search box.
```php
querySearch
https://techblog.example.com/search
*/
} catch (Exception $e) {
echo "TextInput error: " . $e->getMessage();
}
```
--------------------------------
### Channel Methods
Source: https://github.com/aherne/rss-generator/blob/master/README.md
Methods for setting various sub-tags of the RSS channel.
```APIDOC
## Channel Methods
### Description
Methods for setting various sub-tags of the RSS channel.
### Methods
#### addItem
##### Description
Sets the value of the `item` sub-tag.
##### Arguments
- **item** ([Item](#item)) - The item to add.
#### setLanguage
##### Description
Sets the value of the `language` sub-tag.
##### Arguments
- **language** (string) - The language of the channel.
#### setCopyright
##### Description
Sets the value of the `copyright` sub-tag.
##### Arguments
- **copyright** (string) - The copyright information for the channel.
#### setManagingEditor
##### Description
Sets the value of the `managingEditor` sub-tag.
##### Arguments
- **email** (string) - The email address of the managing editor.
#### setWebMaster
##### Description
Sets the value of the `webMaster` sub-tag.
##### Arguments
- **email** (string) - The email address of the webmaster.
#### setPubDate
##### Description
Sets the value of the `pubDate` sub-tag by corresponding unix time.
##### Arguments
- **unixTime** (int) - The unix timestamp for the publication date.
#### setLastBuildDate
##### Description
Sets the value of the `lastBuildDate` sub-tag by corresponding unix time.
##### Arguments
- **unixTime** (int) - The unix timestamp for the last build date.
#### setCategory
##### Description
Sets the value of the `category` sub-tag.
##### Arguments
- **category** (string) - The category of the channel.
#### setGenerator
##### Description
Sets the value of the `generator` sub-tag.
##### Arguments
- **generator** (string) - The generator of the channel.
#### setDocs
##### Description
Sets the value of the `docs` sub-tag.
##### Arguments
- **url** (string) - The URL for the documentation.
#### setCloud
##### Description
Sets the value of the `cloud` sub-tag.
##### Arguments
- **cloud** ([Cloud](https://github.com/aherne/rss-generator/blob/master/src/Cloud.php)) - The cloud object.
#### setTtl
##### Description
Sets the value of the `ttl` sub-tag.
##### Arguments
- **number** (int) - The time-to-live value.
#### setImage
##### Description
Sets the value of the `image` sub-tag.
##### Arguments
- **image** ([Image](https://github.com/aherne/rss-generator/blob/master/src/Image.php)) - The image object.
#### setTextInput
##### Description
Sets the value of the `textInput` sub-tag.
##### Arguments
- **textInput** ([Input](https://github.com/aherne/rss-generator/blob/master/src/Input.php)) - The text input object.
#### setSkipHours
##### Description
Sets the value of the `skipHours` sub-tag.
##### Arguments
- **skipHours** ([SkipHours](https://github.com/aherne/rss-generator/blob/master/src/SkipHours.php)) - The skip hours object.
#### setSkipDays
##### Description
Sets the value of the `skipDays` sub-tag.
##### Arguments
- **skipDays** ([SkipDays](https://github.com/aherne/rss-generator/blob/master/src/SkipDays.php)) - The skip days object.
#### addCustomTag
##### Description
Adds a custom non-standard sub-tag.
##### Arguments
- **tag** ([Tag](#Tag)) - The custom tag to add.
### Response
#### Success Response (void)
These methods do not return a value.
```
--------------------------------
### Add Custom XML Tags to RSS Feed Items (PHP)
Source: https://context7.com/aherne/rss-generator/llms.txt
Implement the Tag interface or use any class implementing \Stringable to create custom XML tags. These can be added to Channel or Item objects using addCustomTag() to extend the feed with non-standard elements like media:content or dc:creator.
```php
{"$this->name"}";
}
}
$channel = new Channel("My Blog", "https://myblog.example.com", "Blog posts");
$item = new Item("My First Post", "Content here.");
$item->addCustomTag(new DcCreator("Jane Doe"));
$channel->addItem($item);
$rss = new RSS($channel);
$rss->addNamespace("dc", "http://purl.org/dc/elements/1.1/");
echo $rss;
/*
...
My First PostJane Doe
*/
?>
```
--------------------------------
### Exclude Specific Days from Feed Aggregation (PHP)
Source: https://context7.com/aherne/rss-generator/llms.txt
Use SkipDays to define days of the week when aggregators should not fetch the feed. Only full English day names (Monday–Sunday) are accepted. The constructor throws an exception for unrecognized day names.
```php
SaturdaySunday
*/
} catch (Exception $e) {
// Thrown for unrecognised day names
echo "SkipDays error: " . $e->getMessage();
}
?>
```
--------------------------------
### Item — Individual Feed Entry
Source: https://context7.com/aherne/rss-generator/llms.txt
Represents a single article or entry within an RSS channel. Title and description are required.
```APIDOC
## Item — Individual Feed Entry
`Item` represents a single article or entry inside a channel. Only title and description are required; all other fields are optional.
```php
Named arguments improve code readability." // HTML is CDATA-escaped
);
$item->setLink("https://techblog.example.com/php-83-named-args");
$item->setAuthor("jane@techblog.example.com");
$item->setCategory("PHP");
$item->setComments("https://techblog.example.com/php-83-named-args#comments");
$item->setGuid("https://techblog.example.com/php-83-named-args");
$item->setPubDate(strtotime("2024-05-20")); // converted to RFC-822
$item->setSource("https://php.net/feed");
// Attach a podcast/media enclosure
$item->setEnclosure(new Enclosure(
"https://techblog.example.com/audio/ep42.mp3",
20480000, // byte size
"audio/mpeg" // MIME type
));
echo $item;
/*
PHP 8.3 Named ArgumentsNamed arguments improve code readability.]]>
https://techblog.example.com/php-83-named-args
jane@techblog.example.com
...
*/
} catch (Exception $e) {
echo "Item error: " . $e->getMessage();
}
```
```
--------------------------------
### Channel - Feed Metadata Container
Source: https://context7.com/aherne/rss-generator/llms.txt
The `Channel` class holds essential feed metadata like title, link, and description, and supports various optional sub-tags and items. It allows adding custom tags and individual items.
```APIDOC
## Channel — Feed Metadata Container
`Channel` holds the required feed metadata (title, link, description) and all optional channel-level sub-tags. Items are appended with `addItem()`; arbitrary non-standard tags can be added via `addCustomTag()`.
### Method Signature
```php
public __construct(string $title, string $link, string $description)
public setLanguage(string $language)
public setCopyright(string $copyright)
public setManagingEditor(string $email)
public setWebMaster(string $email)
public setPubDate(int $timestamp)
public setLastBuildDate(int $timestamp)
public setCategory(string $category)
public setGenerator(string $generator)
public setDocs(string $url)
public setTtl(int $minutes)
public setImage(Image $image)
public setCloud(Cloud $cloud)
public setSkipHours(SkipHours $skipHours)
public setSkipDays(SkipDays $skipDays)
public addItem(Item $item)
public addCustomTag(string $name, string $value)
```
### Example Usage
```php
setLanguage("en-us");
$channel->setCopyright("2024 Tech Blog");
$channel->setManagingEditor("editor@techblog.example.com");
$channel->setWebMaster("webmaster@techblog.example.com");
$channel->setPubDate(strtotime("2024-06-01")); // converted to RFC-822
$channel->setLastBuildDate(strtotime("2024-06-15"));
$channel->setCategory("Technology");
$channel->setGenerator("Lucinda RSS Library");
$channel->setDocs("https://www.rssboard.org/rss-specification");
$channel->setTtl(60); // cache for 60 minutes
// Attach optional sub-objects
$channel->setImage(new Image(
"https://techblog.example.com/logo.png",
"Tech Blog Logo",
"https://techblog.example.com"
));
$channel->setCloud(new Cloud(
"rpc.techblog.example.com", 80, "/rpc", "pingMe", "soap"
));
$channel->setSkipHours(new SkipHours([0, 1, 2, 3, 4, 5])); // skip midnight–5 AM
$channel->setSkipDays(new SkipDays(["Saturday", "Sunday"]));
$channel->addItem(new Item("Hello World", "Our first post!"));
$channel->addItem(new Item("PHP 8.3 Features", "A deep dive into PHP 8.3."));
echo $channel;
} catch (Exception $e) {
echo "Channel error: " . $e->getMessage();
}
```
```
--------------------------------
### TextInput — Search Box
Source: https://context7.com/aherne/rss-generator/llms.txt
Renders an optional search or input box within an RSS channel.
```APIDOC
## TextInput — Search Box
`TextInput` renders an optional search/input box alongside the channel in RSS readers that support it.
```php
querySearch
https://techblog.example.com/search
*/
} catch (Exception $e) {
echo "TextInput error: " . $e->getMessage();
}
```
```
--------------------------------
### Item Class Methods
Source: https://github.com/aherne/rss-generator/blob/master/README.md
The Item class provides methods to set various properties of an RSS feed item. These methods correspond to standard RSS item tags.
```APIDOC
## Item Class
### Description
Encapsulates the logic for the `` tag in RSS feeds.
### Methods
#### `__construct(string $title, string $description)`
* **Description**: Sets the values for the required `title` and `description` sub-tags of an item. The description is automatically escaped using CDATA.
* **Arguments**:
* `$title` (string) - The title of the RSS item.
* `$description` (string) - The description of the RSS item.
#### `setLink(string $url)`
* **Description**: Sets the value for the `link` sub-tag, specifying the URL associated with the item.
* **Arguments**:
* `$url` (string) - The URL for the item.
#### `setAuthor(string $email)`
* **Description**: Sets the value for the `author` sub-tag, specifying the email address of the item's author.
* **Arguments**:
* `$email` (string) - The email address of the author.
#### `setCategories(string $category)`
* **Description**: Sets the value for the `categories` sub-tag, assigning a category to the item.
* **Arguments**:
* `$category` (string) - The category for the item.
#### `setComments(string $url)`
* **Description**: Sets the value for the `comments` sub-tag, providing a URL for comments related to the item.
* **Arguments**:
* `$url` (string) - The URL for comments.
#### `setEnclosure(Enclosure $enclosure)`
* **Description**: Sets the value for the `enclosure` sub-tag, typically used for media files associated with the item.
* **Arguments**:
* `$enclosure` (Enclosure) - An Enclosure object representing the media.
#### `setGuid(string $guid)`
* **Description**: Sets the value for the `guid` sub-tag, providing a unique identifier for the item.
* **Arguments**:
* `$guid` (string) - The unique identifier.
#### `setPubDate(int $unixTime)`
* **Description**: Sets the value for the `pubDate` sub-tag using a Unix timestamp.
* **Arguments**:
* `$unixTime` (int) - The publication date as a Unix timestamp.
#### `setSource(string $url)`
* **Description**: Sets the value for the `source` sub-tag, indicating the source of the item's content.
* **Arguments**:
* `$url` (string) - The URL of the source.
#### `addCustomTag(Tag $tag)`
* **Description**: Adds a custom, non-standard sub-tag to the item.
* **Arguments**:
* `$tag` (Tag) - A Tag object representing the custom tag.
```
--------------------------------
### Cloud — Real-Time Update Notification
Source: https://context7.com/aherne/rss-generator/llms.txt
Registers a web service for real-time RSS feed update notifications.
```APIDOC
## Cloud — Real-Time Update Notification
`Cloud` registers a web service that supports the rssCloud interface, allowing subscribers to be notified immediately when the feed is updated.
```php
} catch (Exception $e) {
echo "Cloud error: " . $e->getMessage();
}
```
```
--------------------------------
### Image — Channel Logo
Source: https://context7.com/aherne/rss-generator/llms.txt
Defines the optional logo for an RSS channel. Width and height are optional.
```APIDOC
## Image — Channel Logo
`Image` defines the optional logo displayed alongside the channel. Width and height are optional; description is auto-CDATA-escaped.
```php
setWidth(144);
$image->setHeight(144);
$image->setDescription("The official Tech Blog logo");
echo $image;
/*
https://techblog.example.com/logo.pngTech Blog
https://techblog.example.com
144144
*/
} catch (Exception $e) {
echo "Image error: " . $e->getMessage();
}
```
```
--------------------------------
### RSS - Root Feed Object
Source: https://context7.com/aherne/rss-generator/llms.txt
The `RSS` class is the top-level object that encapsulates the `Channel` and generates the complete RSS XML document. It allows for the registration of custom XML namespaces.
```APIDOC
## RSS - Root Feed Object
`RSS` is the top-level class that wraps a `Channel` and serializes the complete `…` document. Custom XML namespaces (e.g., `media:`, `dc:`) can be registered via `addNamespace()`.
### Method Signature
```php
public __construct(Channel $channel)
public addNamespace(string $prefix, string $uri)
```
### Example Usage
```php
addItem(new Item("Release 3.0", "Version 3.0 is now available."));
$rss = new RSS($channel);
// Register a custom namespace (e.g., Dublin Core)
$rss->addNamespace("dc", "http://purl.org/dc/elements/1.1/");
// Output the full XML document
header("Content-Type: application/rss+xml; charset=UTF-8");
echo $rss;
/*
Lucinda Framework
https://www.lucinda-framework.com
Release 3.0
*/
} catch (Exception $e) {
// Thrown when addNamespace receives an invalid URL
echo "Error: " . $e->getMessage();
}
```
```
--------------------------------
### Wrap Text in CDATA Section (PHP)
Source: https://context7.com/aherne/rss-generator/llms.txt
The Escape class wraps arbitrary text within a `` section, ensuring safe transmission of HTML or special characters. This is useful for descriptions or custom tags.
```php
Hello World & everyone!";
$escaped = new Escape($raw);
echo $escaped;
// Hello World & everyone!]]>
?>
```
--------------------------------
### Exclude Specific Hours from Feed Aggregation (PHP)
Source: https://context7.com/aherne/rss-generator/llms.txt
Use SkipHours to specify a range of hours (UTC) during which aggregators should not fetch the feed. The constructor validates that all provided hour values are integers between 0 and 23.
```php
0123456
*/
} catch (Exception $e) {
// Thrown if any value is outside 0–23
echo "SkipHours error: " . $e->getMessage();
}
?>
```
--------------------------------
### RSS Class
Source: https://github.com/aherne/rss-generator/blob/master/README.md
The RSS class encapsulates the main rss tag logic. It requires a Channel object upon construction and allows for adding custom namespaces.
```APIDOC
## RSS Class
### Description
Encapsulates the main `rss` tag logic for the feed. It requires a `Channel` object during construction and provides a method to add custom namespaces.
### Methods
#### `__construct(Channel $channel)`
- **Description**: Constructs the RSS feed based on the mandatory `Channel` object.
- **Arguments**:
- `$channel` (Channel): The channel object containing feed metadata and items.
#### `addNamespace(string $name, string $url)`
- **Description**: Adds a custom RSS namespace to the feed, enabling the inclusion of non-standard tags.
- **Arguments**:
- `$name` (string): The name of the namespace.
- `$url` (string): The URL of the namespace.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.