Napisałem sobie klasę do generowania RSS 2.0, ale nie działa :/
<?php
class RSS{
#gen - generowanie na bieżąco, file - zapis do pliku
var $method = 'gen';
#jeśli method=file zmienna ta określa plik do którego ma zostać zapisana zawartość kanału
var $file;
# Nagłowki kanału, tytuł, opis i link do strony
function RSS($title, $description, $link){
if($method=='gen'){
echo '<?xml version="1.0" encoding="UTF-8"?>\n'; echo '<rss version="2.0">\n'; echo '<title>'.$title.'</title>\n'; echo '<link>'.$link.'</link>\n'; echo '<description>'.$description.'</description>\n'; } elseif($method=='file' and
!empty($file) and
is_file($file)){ fwrite($h,'<?xml version="1.0" encoding="UTF-8"?>\n <rss version="2.0">\n
<channel>\n
<title>'.$title.'</title>\n
<link>'.$link.'</link>\n
<description>'.$description.'</description>\n');
}
}
function addNews($newstitle, $pubdate, $newslink, $newsdesc){
if($method=='gen'){
echo '<title>'.$newstitle.'</title>\n'; echo '<pubDate>'.$pubdate.'</pubDate>\n'; echo '<link>'.$newslink.'</link>\n'; echo '<description>'.$newsdesc.'</description>\n'; } elseif($method=='file' and
!empty($file) and
is_file($file)){ <title>'.$newstitle.'</title>\n
<pubDate>'.$pubdate.'</pubDate>\n
<link>'.$newslink.'</link>\n
<description>'.$newsdesc.'</description>\n
</item>\n');
}
}
function closeFile(){
if($method=='gen'){
} elseif($method=='file' and
!empty($file) and
is_file($file)){ </rss>\n');
}
}
}
?>
Wywołałem tak:
<?php
include "rss.class.php";
$rss = new RSS('Mój kanał RSS', 'Opis kanału', 'http://example.com');
$rss->method='gen';
$rss->addNews('Nius', '2008-10-07 19:00:00', 'http://example.com/?news_id=6', 'Treść wiadomości.');
$rss->closeFile();
?>
Nic się nie dzieje, macie jakieś pomysły?