Am sa continui seria de articole mai tehnice, cu o solutie legata de o metoda rapida de constructie RSS. Se da o tabela in MySql si se doreste o soluti rapida de expunere a unui RSS feed.
Solutia?
<?php
function getHeader($titlu, $link, $descriere)
{
header (‘Content-type: text/xml’);
echo ‘<?xml version=”1.0″ ?>
<rss version=”2.0″>
<channel>
<title>’. $titlu .’</title>
<link>’. $link .’</link>
<description>’. $descriere .’</description>
<generator>Php</generator>’;
}
function getFooter()
{
echo ‘
</channel>
</rss>’;
}
//include baza de date
require_once($_SERVER['DOCUMENT_ROOT'] . “/include/config.inc.php”);
$db=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbdatabase);
$feed_action = $_GET['modul'];
if ($feed_action == ’stiri’)
{
getStiri(“Ultimle stiri”, “http://www.stiri.ro/”, “Ultimele stiride de pe stiri.ro”);
}
//add the footer
getFooter();
//get RSS for stiri
function getStiri$titlu, $link, $descriere)
{
getHeader($titlu, $link, $descriere);
//genereaza elementele
$map_result = mysql_query(“SELECT id, stire, data_adaugare FROM stiri WHERE aprobat = 1 order by id desc limit 0,10″);
while ($map_row = mysql_fetch_array($map_result)) {
echo ‘
<item>
<title>Stirea cu numarul ‘. $map_row['id'] .’</title>
<description><![CDATA['. $map_row['stire'] .’]]></description>
<link>http://www.stire.ro/detalii/id/’. $map_row['id'] .’/</link>
<pubDate>’. $map_row['data_adaugare'] .’</pubDate>
</item>’;
}
}
?>

Imi poti spune mai exact unde se pune acest cod ? Pentru ca as dori sa`mi si eu RSS pe site dar nu stiu exact unde sa pun codul !
Poate fi adaptat acest cod pentru a face un singur feed din mai multe site-uri?
Foarte tare. Nu stiam. Ms moolt.