1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| <?
//édition du début du fichier xml
$xml='<?xml version="1.0" encoding="ISO-8859-1"?>';
$xml.='<rss version="2.0">';
$xml.='<channel>';
$xml.='<title>PROJET CNAM</title>';
$xml.='<link>http://127.0.0.1/BDD</link>';
$xml.='<description>test RSS projet CNAM</description>';
$xml.='<pubDate>Mardi 11 Avril 2006</pubDate>';
//Connection à la base de donné et sélection de la table
$host = "localhost";
$base = "CNAM_PROJET";
$user = "root";
$pwd = "";
@mysql_connect($host,$user,$pwd) or die("connexion impossible");
@mysql_select_db($base) or die("Echec de selection de la base");
//selection des dix dernirères news
$requete="SELECT * FROM news, users WHERE news.auteur=users.id_users order by date desc limit 0, 10";
$res=mysql_query($requete);
//Extraction des informations et ajout au contenu
while($tab=mysql_fetch_array($res)){
$titre=$tab['titre'];
$id_news=$tab['id_news'];
$auteur=$tab['nom_user'];
$id_news=urldecode($id_news);
$contenu=$tab['contenu'];
$date=$tab['date'];
setlocale(LC_TIME, "fr");
$pubDate=date("r", strtotime($date));
$xml.='<item>';
$xml.='<title>'.$titre.'</title>';
$xml.='<link>http://portable/BDD/index.php?page=news&id_news='.$id_news.'</link>';
$xml.='<author>'.$auteur.'</author>';
$xml.='<description>'.$contenu.'</description>';
$xml.='<pubDate>'.$pubDate.'</pubDate>';
$xml.='</item>';
}
//Fermeture des balises channel et rss
$xml.='</channel>';
$xml.='</rss>';
//Ecriture dans le fichier xml
$fp=fopen("rss.xml","w");
fwrite($fp, $xml);
fclose($fp);
echo 'Export XML effectue !<br><a href="rss.xml">Voir le fichier</a>';
//echo $xml;
?> |
Partager