8795 sujets

Développement web côté serveur, CMS

Bonjour,

J'ai développé une google map où s'affichent différents marqueurs provenant d'une base SQL.
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

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
<?php
require("./phpsqlajax_dbinfo.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&apos;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
$xmlStr=str_replace("é",'&eacute;',$xmlStr);
$xmlStr=str_replace("è",'&egrave;',$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.... ?
Merci
Modifié par CyberNord (22 Jan 2011 - 16:13)
http://us2.php.net/manual/fr/function.utf8-encode.php

a écrit :
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 ?
Modifié par CyberNord (21 Jan 2011 - 20:29)
J'ai essayé avec :

$encoded=$row['name'];
$encoded=htmlspecialchars($encoded);
$encoded=utf8_encode($encoded);
echo 'name="' .$encoded. '" ';


avec succès Smiley biggrin
Modifié par CyberNord (21 Jan 2011 - 21:31)