Je cherche à mettre un fux rss sur un site mais quand je consulte le flux je constate qu'à la place de mes apostrophes avec FF il m'affiche des signes chinois et sous IE il n'en tient pas compte. Ma BDD, ma table, mes champs sont en utf8. Quelqu'un s'y connaissant pourrait-il m'aider s'il vous plaît. Merci par avance. Je vous vous mets ci-dessous mon script.
fichier flus rss
<?php
function &init_news_rss(&$xml_file)
{
$root = $xml_file->createElement("rss"); // création de l'élément
$root->setAttribute("version", "2.0"); // on lui ajoute un attribut
$root = $xml_file->appendChild($root); // on l'insère dans le noeud parent (ici root, qui est "rss")
$channel = $xml_file->createElement("channel");
$channel = $root->appendChild($channel);
$desc = $xml_file->createElement("description");
$desc = $channel->appendChild($desc);
$text_desc = $xml_file->createTextNode("madescription"); // on insère du texte entre les balises <description></description>
$text_desc = $desc->appendChild($text_desc);
$link = $xml_file->createElement("link");
$link = $channel->appendChild($link);
$text_link = $xml_file->createTextNode("http://www.site.com");
$text_link = $link->appendChild($text_link);
$title = $xml_file->createElement("title");
$title = $channel->appendChild($title);
$text_title = $xml_file->createTextNode("site.com");
$text_title = $title->appendChild($text_title);
return $channel;
}
function add_news_node(&$parent, $root, $id_billet, $auteur, $titre, $resume, $date)
{
$item = $parent->createElement("item");
$item = $root->appendChild($item);
$title = $parent->createElement("title");
$title = $item->appendChild($title);
$text_title = $parent->createTextNode($titre);
$text_title = $title->appendChild($text_title);
$link = $parent->createElement("link");
$link = $item->appendChild($link);
$text_link = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets='.$id_billet");
$text_link = $link->appendChild($text_link);
$desc = $parent->createElement("description");
$desc = $item->appendChild($desc);
$text_desc = $parent->createTextNode($resume);
$text_desc = $desc->appendChild($text_desc);
$com = $parent->createElement("comments");
$com = $item->appendChild($com);
$text_com = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets='.$id_billet");
$text_com = $com->appendChild($text_com);
$author = $parent->createElement("author");
$author = $item->appendChild($author);
$text_author = $parent->createTextNode($auteur);
$text_author = $author->appendChild($text_author);
$pubdate = $parent->createElement("pubDate");
$pubdate = $item->appendChild($pubdate);
$text_date = $parent->createTextNode($date);
$text_date = $pubdate->appendChild($text_date);
$guid = $parent->createElement("guid");
$guid = $item->appendChild($guid);
$text_guid = $parent->createTextNode("http://www.site.com/controleur/commentaire/index.php?billets='.$id_billet");
$text_guid = $guid->appendChild($text_guid);
$src = $parent->createElement("source");
$src = $item->appendChild($src);
$text_src = $parent->createTextNode("http://www.site.com");
$text_src = $src->appendChild($text_src);
}
function rebuild_rss()
{
// on se connecte à la BDD
try
{
$bdd = new PDO('mysql:host=localhost;dbname=mabdd','monidentifiant','mommotdepasse' );
}
catch(Exception $e)
{
die ('Erreur:'.$e->getMessage());
}
$req = $bdd->query('SELECT id_billet, titre, resume,auteur,DATE_FORMAT(date_de_creation,\'%d/%m/%Y à %Hh%imin%ss\') AS date_de_creation_fr FROM tableau ORDER BY date_de_creation DESC LIMIT 0,5');
// on crée le fichier XML
$xml_file = new DOMDocument("1.0");
$channel = init_news_rss($xml_file);
// on ajoute chaque news au fichier RSS
while( $donnees = $req->fetch() )
{
add_news_node($xml_file, $channel, utf8__encode($donnees["id_billet"]), utf8__encode($donnees["auteur"]), utf8__encode($donnees["titre"]),
utf8__encode($donnees["resume"]), utf8__encode($donnees["date_de_creation"]));
}
// on écrit le fichier
$xml_file->save("rss.xml");
}
rebuild_rss();
?>