Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & MySQL
PHP & MySQL Forum d'entraide sur les fonctions MySQL avec PHP. Avant de poster -> FAQ MySQL, Cours MySQL et Sources MySQL. Pour les questions concernant le moteur MySQL plutôt que les fonctions PHP, merci d'utiliser le forum MySQL.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 21/01/2011, 20h27   #1
Invité de passage
 
Inscription : mars 2008
Messages : 9
Détails du profil
Informations forums :
Inscription : mars 2008
Messages : 9
Points : 2
Points : 2
Par défaut Google Map : affichage des caractères spéciaux

Bonjour,

J'ai développé une google map où s'affichent différents marqueurs provenant d'une base SQL (cf http://code.google.com/intl/fr/apis/...qlajax_v3.html)
Le pb provient des caractères spéciaux qui ne s'affichent pas correctement.

http://chti.sportif.free.fr/calendrier_sports.php

J'ai trouvé une solution temporaire de dépannage en encodant moi-même tous les caractères spéciaux de mon fichier .CSV mais c'est bien sûr peu pratique

Mon fichier .csv pour l'import des données dans MySQL avec un exemple

Code :
13 février 2011,puce_rouge.png,co,50.64227621899096,3.0030441284179688,LOMME,O² Régionale LNPCO,CO régionale Sprint,http://www.opale-orientation.com/,test.htm,http://chti.sportif.free.fr/fiche_de_course.htm,
le fichier .php qui recupère les infos de la table
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
<?php
require("./phpsqlajax_dbinfo.php");
 
function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','"',$xmlStr); 
$xmlStr=str_replace("'",'&apos;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr);  
 
return $xmlStr; 
} 
 
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}
 
// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}
 
// Select all the rows in the markers table
$query = "SELECT * FROM markers_calendrier WHERE 1";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}
 
header("Content-type: text/xml");
 
// Start XML file, echo parent node
echo '<markers>';
 
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'date="' . parseToXML($row['date']) . '" ';
  echo 'puce="' . parseToXML($row['puce']) . '" ';
  echo 'category="' . parseToXML($row['category']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'ville="' . parseToXML($row['ville']) . '" ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'info="' . parseToXML($row['info']) . '" ';
  echo 'link="' . parseToXML($row['link']) . '" ';
  echo 'fiche="' . parseToXML($row['fiche']) . '" ';
  echo 'infoUrl="' . parseToXML($row['infoUrl']) . '" ';
  echo 'photo="' . parseToXML($row['photo']) . '" ';
  echo '/>';
}
 
// End XML file
echo '</markers>';
 
?>
Comment résoudre ce pb pour que je puisse écrire normalement dans mon fichier .CSV ?
Encodage des pages (ANSI, UTF8.. ?.), import du fichier .csv, charset.... ?

http://us2.php.net/manual/fr/function.utf8-encode.php

Citation:
Using PHP's echo to output XML

If you don't have access to PHP's dom_xml functions, then you can simply output the XML with the echo function. When using just the echo function, you'll need to use a helper function (e.g. parseToXML) that will correctly encode a few special entities (<,>,",') to be XML friendly.

In the PHP, first connect to the database and execute the SELECT * (select all) query on the markers table. Then echo out the parent markers node, and iterate through the query results. For each row in the table (each location), you need to echo out the XML node for that marker, sending the name and address fields through the parseToXML function first in case there are any special entities in them. Finish the script by echoing out the closing markers tag.

Note: If your database contains international characters or you otherwise need to force UTF-8 output, you can use utf8_encode on the outputted data.
Je n'y connais rien en php. Que dois je faire ?
merci
Rem5962 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/01/2011, 21h12   #2
Invité de passage
 
Inscription : mars 2008
Messages : 9
Détails du profil
Informations forums :
Inscription : mars 2008
Messages : 9
Points : 2
Points : 2
J'ai essayé avec :

Code :
1
2
3
4
$encoded=$row['name'];
$encoded=htmlspecialchars($encoded);
$encoded=utf8_encode($encoded);
echo 'name="' .$encoded. '" ';
ou tout simplement :
Code :
echo 'name="' . parseToXML(utf8_encode($row['name'])) . '" ';
Avec succès
Rem5962 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h31.


 
 
 
 
Partenaires

Hébergement Web