Bonsoir à tous,
voici mon soucis :
J'utilise simplexml pour l'ajout de données provenant d'un formulaire dans un fichier XML pour cela j'utilise le code suivant :
Mon fichier XML est bien enregistré en UTF-8 et comporte bien l'entête :
Code : Sélectionner tout - Visualiser dans une fenêtre à part $prod->addChild('description',utf8_encode(stripcslashes($_POST['description'])));
Dans mon fichier page.tpl j'ai placé la balise meta :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2<?xml version="1.0" encoding="UTF-8"?>
et dès ke je lance l'affichage j'obtiens une page avec des caractères accentués tels que ceux-ci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
é à ù respéctivement pour les caractères: é à ù
Je ne comprend vraiment pas pourquoi étant donné tout ce ke je vous ai ennoncé avant.
voici le code complet de mes pages :
index.php5 :
page.tpl :
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 <?php include("upload.class.php5"); require_once("Smarty/Smarty.class.php"); $smarty = new Smarty(); // Page d'accueil ou par défaut' switch($_GET['page']){ case "admin": $smarty->assign('contenu',' <h2>Gestion des produits</h2> <form action="" name="upload" method="post" enctype="multipart/form-data"> <fieldset> <legend>Nouveau produit</legend> <input type="hidden" name="file" /><br /> photos: <input type="file" name="file" /><br /> <p>Nom Produit: <input type="texte" name="libelle" /></p> <p>Description du produit: <br /><textarea cols="50" rows="10" name="description"></textarea></p>'."\n".' <p>Prix: <input type="text" name="prix" /></p> <p>Promotion: oui<input type="radio" id="promoOui" name="promo" value="oui">non<input type="radio" id="promoNon" name="promo" value="non" checked></p> <p id="ancienPrix"></p> <input type="submit" name="envoyer" value="envoyer" /> </fieldset> </form>'); if(!empty($_FILES['file'])){ $handle = new Upload($_FILES['file']); if ($handle->uploaded) { $handle->Process('./photos'); $thumb = $handle->file_dst_pathname; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 200; $handle->Process('./photos'); if ($handle->processed) $handle->clean(); $xml = simplexml_load_file('listingProd.xml'); $prod = $xml->addChild('produit'); $prod->addChild('libelle',utf8_encode(stripcslashes($_POST['libelle']))); $prod->addChild('path',$handle->file_dst_pathname); $prod->addChild('path_thumb',$thumb); $prod->addChild('prix',$_POST['prix']); $prod->addChild('description',utf8_encode(stripcslashes($_POST['description']))); $prod->addChild('promotion',$_POST['promo']); $prod->addChild('dateFin',$_POST['dateFin']); $prod->addChild('ancienPrix',$_POST['ancienPrix']); $fic = $xml->asXML(); file_put_contents('listingProd.xml', $fic); } } break; // Assignation dans tous les cas $smarty->assign('menu',' <li><a href="index.php5?page=accueil">Accueil</a></li> <li><a href="index.php5?page=recrutement">Offre d\'emploi</a></li> <li><a href="index.php5?page=produits">Nos produits</a></li> '); $smarty->display('page.tpl'); $smarty->clear_all_assign(); ?>
et un exemple du fichier listingProg.xml généré par le code :
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
49
50
51
52
53
54
55
56
57
58
59
60
61 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Language" content="fr" /> <title>{$title}</title> <LINK rel="stylesheet" type="text/css" href="style.css"> <SCRIPT LANGUAGE="JavaScript" SRC="jquery-1.3.2.js"></SCRIPT> {literal} <SCRIPT language="Javascript"> var check=false; function init(){ $("#promoOui").bind("click",function(){ $("#ancienPrix").append("Ancien prix <input type='text' name='ancienPrix'><br /> Date fin: <input type='text' name='dateFin'>"); }); $("#promoNon").bind("click",function(){ $("#ancienPrix").empty(); }); } </SCRIPT> {/literal} </head> <body onload="init();"> <div id="conteneur"> <h1 id="header"> <a href="index.php" title="Accueil"><span>Page</span></a></h1> <ul id="menu"> {$menu} </ul> <div id="contenu"> <h2>{$titre}</h2> <p>{$contenu} </p> <div id="listProd"> {foreach from=$list item=produit} <div id="produit"> {if $produit->promotion=='oui'}<img src="./images/promo.gif"/>{/if} <div id="libProd">{$produit->libelle}</div> <table> <tr> <td><a href="{$produit->path_thumb}"><img src="{$produit->path}"/></a></td> <td><p class='descProd'>{$produit->description}</p></td> </tr> </table> <div id="prixProd"> {if $produit->promotion=='oui'}<span id="ancienPrix">{$produit->ancienPrix}</span> =>{/if} <span id="nouveauPrix">{$produit->prix}</span> </div> </div> {/foreach} </div> </div> <p id="footer">Copyright</p> </div> </body> </html>
Merci à tous ceux qui pourront m'aider
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12<?xml version="1.0" encoding="UTF-8"?> <listing> <produit> <libelle>kirk hammet é</libelle> <path>./photos/Kirk_Hammett_Escape06_1280_5.jpg</path> <path_thumb>./photos/Kirk_Hammett_Escape06_1280_4.jpg</path_thumb> <prix>1</prix> <description>é à ù</description> <promotion>non</promotion> <dateFin/> </produit> </listing>
![]()
Partager