Bonjour,
Voilà j'essaye de générer un fichier xml avec du php et j'ai des erreurs du style :
Voilà le code PHPThis 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.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?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="http://purl.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="http://purl.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>'; ?>
Partager