Problème d'encodage avec un fichier XML

Fermé
anto2b Messages postés 119 Date d'inscription jeudi 21 février 2008 Statut Membre Dernière intervention 18 décembre 2011 - 4 déc. 2011 à 11:20
Bonjour,

Voilà j'essaye de générer un fichier xml avec du php et j'ai des erreurs du style :

This page contains the following errors:

error on line 2 at column 10: Entity 'nbsp' not defined
error on line 2 at column 10: Encoding error
Below is a rendering of the page up to the first error.



Voilà le code PHP

<?php

try
{
	$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
	$bdd = new PDO('mysql:host=localhost;dbname=fluxrss','root','', $pdo_options);
}
catch (Exception $e)
{
        die('Erreur : ' . $e->getMessage());
}
 $xml = '<?xml version="1.0" encoding="ISO_8859-1" ?>';
 $xml .= '<rss xmlns:content="https://web.resource.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="https://web.resource.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">'; 
 $xml .= '<channel>'; 
 $xml .= '<title>Flux RSS</title>';
 $xml .= '<link>http://www.monfluxrss.com</link>';
 $xml .= '<description>Flux RSS</description>';
 $xml .= '<copyright> Flux RSS</copyright>';
 $xml .= '<language>fr</language>';
 $today= date("D, d M Y H:i:s +0100");
 $xml .= '<pubDate>'.$today.'</pubDate>'; 
 $req_xml = $bdd->query("SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type='post'  ORDER BY post_date DESC limit 0, 10");
	while ($lig = $req_xml->fetch()) 
	{ 
    $titre=$lig["post_title"];
    $adresse=$lig["post_name"];
    $contenu=$lig["post_content"];
    $date=$lig["post_date"];
    $xml .= '<item>';
    $xml .= '<title>'.$titre.'</title>';
    $xml .= '<link>'.$adresse.'</link>';
    $xml .= '<guid>'.$adresse.'</guid>';
    $xml .= '<pubDate>'.$date.'</pubDate>'; 
    $xml .= '<description>'.$contenu.'</description>';
    $xml .= '</item>'; 
	}
$req_xml->closeCursor();
//fin du while
$xml .= '</channel>';
$xml .= '</rss>';
  
  $fp = fopen("fluxrss.xml", 'w+');
  fputs($fp, $xml);
  fclose($fp);
  
  echo 'Export XML effectue !<br /><a href="fluxrss.xml">Voir 
  le fichier</a>';
  ?>