problème Caractères spéciaux
Bonjour, j'essai actuellement de récupéré des données de ma bdd en passant par un fichier php qui me créé un fichier xml pour ensuite le récupéré en Java.
Mon problème est que parfois dans ma bdd j'ai soit des caractères du genre é ou soit des balises <b> par exemple.
Du coup un fois mon fichier xml généré, il me créé une erreur a cause de ces caractères la.
j'ai essayé avec htmlspecialchars() mais ça ne change rien ><
Que puis je faire ? ( soyez indulgent je débute :? )
Cordialement.
Code:
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 68 69 70 71 72 73 74 75 76 77
| <?php
include("connect.php");
$link = mysql_connect($db_host, $db_user, $db_pass) or mysql_error();
$conn = mysql_select_db($db_name);
mysql_select_db($conn, $link);
//OuvertureCréation du fichier test.xml dans le dossier courant
//w : Ouvre en écriture seule : place le pointeur de fichier au début du fichier et réduit la taille du fichier à 0. Si le fichier n'existe pas, on tente de le créer.
$file = fopen("test.xml", "w");
$_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
//Dans cette 1ere ligne, définissant notre XML,
//on découvre le 1er élément important: '\r\n'.
//\r\n signale un retour chariot, puis une nouvelle ligne.
//Vestige d'une histoire passée.
//Cela nous permet de sauter une ligne dans notre nouveau fichier.
//Le XML est défini, il ne reste plus qu'a le remplir :
//Je reprend le même exemple que précédemment
$sql = mysql_query('SELECT * FROM products');
$_xml .= "<cigway>\r\n";
//Le '.' devant le '=' est important,
//on ajoute du contenu à celui déjà présent dans la variable.
while($row = mysql_fetch_array($sql, MYSQL_ASSOC)){
$_xml .="<products>\r\n";
$_xml .="<id_product>". htmlspecialchars($row["id_product"])."</id_product>\r\n";
$_xml .="<cat>". htmlspecialchars($row["cat"])."</cat>\r\n";
$_xml .="<code>". htmlspecialchars($row["code"])."</code>\r\n";
$_xml .="<concentration>". htmlspecialchars($row["concentration"])."</concentration>\r\n";
$_xml .="<gout>". htmlspecialchars($row["gout"])."</gout>\r\n";
$_xml .="<couleur>". htmlspecialchars($row["couleur"])."</couleur>\r\n";
$_xml .="<title_fr>". htmlspecialchars($row["title_fr"])."</title_fr>\r\n";
$_xml .="<title_fr_cart>". htmlspecialchars($row["title_fr_cart"])."</title_fr_cart>\r\n";
$_xml .="<cara_fr>". htmlspecialchars($row["cara_fr"])."</cara_fr>\r\n";
$_xml .="<cara_fr_product>". htmlspecialchars($row["cara_fr_product"])."</cara_fr_product>\r\n";
$_xml .="<price>". htmlspecialchars($row["price"])."</price>\r\n";
$_xml .="<discount>". htmlspecialchars($row["discount"])."</discount>\r\n";
$_xml .="<price_promo>". htmlspecialchars($row["price_promo"])."</price_promo>\r\n";
$_xml .="<port>". htmlspecialchars($row["port"])."</port>\r\n";
$_xml .="<homepage>". htmlspecialchars($row["homepage"])."</homepage>\r\n";
$_xml .="<defaultpic>". htmlspecialchars($row["defaultpic"])."</defaultpic>\r\n";
$_xml .="<created>". htmlspecialchars($row["created"])."</created>\r\n";
$_xml .="<distributeur>". htmlspecialchars($row["distributeur"])."</distributeur>\r\n";
$_xml .="<stock>". htmlspecialchars($row["stock"])."</stock>\r\n";
$_xml .="<ref_logistique>". htmlspecialchars($row["ref_logistique"])."</ref_logistique>\r\n";
$_xml .="<volume_logistique>". htmlspecialchars($row["volume_logistique"])."</volume_logistique>\r\n";
$_xml .="<sell_admin>". htmlspecialchars($row["sell_admin"])."</sell_admin>\r\n";
$_xml .="<ref_facturation>". htmlspecialchars($row["ref_facturation"])."</ref_facturation>\r\n";
$_xml .="<alt_img_product>". htmlspecialchars($row["alt_img_product"])."</alt_img_product>\r\n";
$_xml .="<url_rw>". htmlspecialchars($row["url_rw"])."</url_rw>\r\n";
$_xml .="<ean>". htmlspecialchars($row["ean"])."</ean>\r\n";
$_xml .= "</products>\r\n";
}
$_xml .= "</cigway>\r\n";
//Pour faire simple : Là ou nous mettions 'echo',
//il suffit de mettre $_xml .= "... \r\n"
//fwrite(); se définit avec deux paramètres :
//1. Le fichier où l'on écrit
//2. Le contenu a écrire
fwrite($file, $_xml);
//on ferme le fichier
fclose($file);
?> |