channelTitle = $title; $this->channelLink = $link; $this->channelDescription = $description; } /** * Add an item to the RSS feed. * * @param string $title Item title. * @param string $description Item description. * @param string $link Item URL. * @param string $pubDate A date/time string (accepted by strtotime). */ public function addItem(string $title, string $description, string $link, string $pubDate): void { $this->items[] = [ 'title' => htmlspecialchars($title), 'description' => htmlspecialchars($description), 'link' => $link, 'guid' => $link, 'pubDate' => date($this->pubDateFormat, strtotime($pubDate)) ]; } /** * Generate the complete RSS XML. * * @return string The RSS XML string. */ public function generateXML(): string { $xml = '' . "\n"; $xml .= '' . "\n"; $xml .= " \n"; $xml .= " {$this->channelTitle}\n"; $xml .= " {$this->channelLink}\n"; $xml .= " {$this->channelDescription}\n"; $xml .= " " . date($this->pubDateFormat) . "\n"; // Optionally add additional channel tags here foreach ($this->items as $item) { $xml .= " \n"; $xml .= " {$item['title']}\n"; $xml .= " {$item['description']}\n"; $xml .= " {$item['link']}\n"; $xml .= " {$item['guid']}\n"; $xml .= " {$item['pubDate']}\n"; $xml .= " \n"; } $xml .= " \n"; $xml .= ""; return $xml; } }