Accueil > > > EXEMPLE SIMPLE DE GÉNÉRATION DE FLUX RSS
EXEMPLE SIMPLE DE GÉNÉRATION DE FLUX RSS
Information sur la source
Description
Dans le même esprit que le code : - http://www.aspfr.com/code.aspx?ID=25633 Voici un exemple simple de génération de flux RSS depuis une table simple contenant les informations suivantes : - ID : Id de la nouvelle en cours - AUTEUR : Auteur de la nouvelle en cours - DATENEWS : Date de la nouvelle en cours - MESSAGE : Message de la nouvelle
Source
- <?
- $dbhost = "VotreServeurMySQL";
- $dblogi = "VotreLogin";
- $dbpass = "VotrePassWord";
- $dbbase = "VotreBase";
-
- $db = @mysql_connect("$dbhost", "$dblogi", "$dbpass") OR DIE("Désolé, la Base est Down !");
- @mysql_select_db("$dbbase",$db) OR DIE;
-
- $query = "SELECT * FROM NOUVELLES ORDER BY DATENEWS DESC";
- $result = mysql_query ($query) or die("La requette a échouée : ".mysql_error());
- $nb_msg = mysql_num_rows($result);
-
- header("Content-Type: text/xml");
-
- $xml = '<'.'?xml version="1.0" encoding="UTF-8"?'.'><rss version="2.0"><channel>';
-
- $xml .='<title>Exemple de flux RSS en PHP</title>';
- $xml .='<link>http://www.phpcs.com</link>';
- $xml .='<description>Les dernières nouvelles</description>';
- $xml .='<managingEditor>adressemail@fournisseur.com</managingEditor>';
- $xml .='<language>fr</language>';
- $xml .='<generator>PHPCS</generator>';
- $xml .='<copyright>PHPCS</copyright>';
- $xml .='<webMaster>PHPCS Webmaster</webMaster>';
-
- while ($msg_data = mysql_fetch_array($result))
- {
- $id = $msg_data['ID'];
-
- $titre = $msg_data['AUTEUR']." - Nouvelle Du Site";
- $news = stripslashes(trim($msg_data['MESSAGE']));
- $news = str_replace("<BR>",'<BR/>',$news);
- $news = str_replace("&",'&',$news);
- $news = str_replace("<","<",$news);
- $news = str_replace(">",">",$news);
-
- $xml .='<item>';
- $xml .='<author>'.$msg_data['AUTEUR'].'</author>';
- $xml .='<title>'.$titre.'</title>';
- $xml .='<link>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</link>';
- $xml .='<pubDate>'.$msg_data['DATENEWS'].' GMT</pubDate>';
- $xml .='<guid>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</guid>';
- $xml .='<comments>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</comments>';
- $xml .='<description>';
-
- $xml .= $news;
-
- $xml .='</description></item>';
- }
-
- mysql_close();
-
- $xml .='</channel></rss>';
-
- echo $xml;
-
- ?>
<?
$dbhost = "VotreServeurMySQL";
$dblogi = "VotreLogin";
$dbpass = "VotrePassWord";
$dbbase = "VotreBase";
$db = @mysql_connect("$dbhost", "$dblogi", "$dbpass") OR DIE("Désolé, la Base est Down !");
@mysql_select_db("$dbbase",$db) OR DIE;
$query = "SELECT * FROM NOUVELLES ORDER BY DATENEWS DESC";
$result = mysql_query ($query) or die("La requette a échouée : ".mysql_error());
$nb_msg = mysql_num_rows($result);
header("Content-Type: text/xml");
$xml = '<'.'?xml version="1.0" encoding="UTF-8"?'.'><rss version="2.0"><channel>';
$xml .='<title>Exemple de flux RSS en PHP</title>';
$xml .='<link>http://www.phpcs.com</link>';
$xml .='<description>Les dernières nouvelles</description>';
$xml .='<managingEditor>adressemail@fournisseur.com</managingEditor>';
$xml .='<language>fr</language>';
$xml .='<generator>PHPCS</generator>';
$xml .='<copyright>PHPCS</copyright>';
$xml .='<webMaster>PHPCS Webmaster</webMaster>';
while ($msg_data = mysql_fetch_array($result))
{
$id = $msg_data['ID'];
$titre = $msg_data['AUTEUR']." - Nouvelle Du Site";
$news = stripslashes(trim($msg_data['MESSAGE']));
$news = str_replace("<BR>",'<BR/>',$news);
$news = str_replace("&",'&',$news);
$news = str_replace("<","<",$news);
$news = str_replace(">",">",$news);
$xml .='<item>';
$xml .='<author>'.$msg_data['AUTEUR'].'</author>';
$xml .='<title>'.$titre.'</title>';
$xml .='<link>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</link>';
$xml .='<pubDate>'.$msg_data['DATENEWS'].' GMT</pubDate>';
$xml .='<guid>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</guid>';
$xml .='<comments>http://VotreSiteWeb/VotrePagedeLecture.php?ValeurID='.$id.'</comments>';
$xml .='<description>';
$xml .= $news;
$xml .='</description></item>';
}
mysql_close();
$xml .='</channel></rss>';
echo $xml;
?>
Conclusion
Bon coding
Romelard Fabrice (Alias F___)
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA par cyril
Le deuxième keynote du mix fut très riche en contenu. Internet Explorer 9 Juste un après le lancement de Internet Explorer 8, Microsoft a dévoilé les nouveautés de Internet Explorer 9. Désormais, IE supportera HTML5, SVG et CSS3. L'élément ...
Cliquez pour lire la suite de l'article par cyril CERTIFICATIONS BETA .NET 4CERTIFICATIONS BETA .NET 4 par KooKiz
Les inscriptions pour les certifications beta .NET 4 ont commencé. L'inscription est offerte pour les examens suivants : - 71-511, TS: Windows Applications Development with Microsoft .NET Framework 4 - 71-515, TS: Web Applications Development with...
Cliquez pour lire la suite de l'article par KooKiz [MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2[MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2 par redo
J'imagine que la plupart d'entre vous connaissent bien et utilisent le service de traduction de Google, mais connaissez-vous celui de Microsoft . Microsoft Translator ? Effectivement, Microsoft nous annoncé le lancement version 2 de la Technologie Preview...
Cliquez pour lire la suite de l'article par redo LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010!LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010! par MPOWARE
Toutes les vidéos de ce lancement sont en ligne!
Partie I - Intro
http://www.youtube.com/watch?v=LkQzTQ8T6CA
Partie II - Démo 1
http://www.youtube.com/watch?v=drAhYQ7lqvo
Partie III - Démo 2
http://www.youtube.com/watch?v=c8KM_1Gqybc...
Cliquez pour lire la suite de l'article par MPOWARE [WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE[WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE par FREMYCOMPANY
Je pense qu'ils ont besoin d'une piqure de rappel chez Microsoft : c'est bien gentil d'avoir une interface jolie, mais si c'est pour avoir un truc qui ne convainct pas dedans, c'est peine perdue.
---->
Système ouvert ----> Fermé ?
P...
Cliquez pour lire la suite de l'article par FREMYCOMPANY
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|