<?php
const RSS_NAME = 'rss.xml';
const RSS_TITLE = 'Последние новости';
const RSS_LINK = 'http://mysite.local/news/news.php';
public function createRss(){
$dom = new DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$rss = $dom->createElement("rss");
$dom->appendChild($rss);
$version = $dom->createAttribute("version");
$version->value = '2.0';
$rss->appendChild($version);
$channel = $dom->createElement("channel");
$rss->appendChild($channel);
$title = $dom->createElement("title", self::RSS_TITLE);
$link = $dom->createElement("link", self::RSS_LINK);
$channel->appendChild($title);
$channel->appendChild($link);
$data = $this->getNews();
foreach ($date as $d) {
$item = $dom->createElement("item");
$title = $dom->createElement("title", $d['title']);
$link = $dom->createElement("link", $d['source']);
$description = $dom->createElement("description", $d['description']);
$pubDate = $dom->createElement("pubDate", date("d-m-Y",$d['datetime']);
$category = $dom->createElement("category", $d['category']);
$item->appendChild($title);
$item->appendChild($link);
$item->appendChild($description);
$item->appendChild($pubDate);
$item->appendChild($category);
$channel->appendChild($item);
}
$dom->save(self::RSS_NAME);
}
?>