Q: How to decode special charaters Google Maps API V3 using xml from mysql database



I have a decoding problem for my xml file. So i have a Mysql data base for storing pin location and data. I used a xml paser to bring my mysql data to xml, but i have some special charaters (latvian) like ā,š,č,ļ,ī,ē that show up like ? in my xml file. Is there a way how solve it? Here is my code for xml parser



<?php

require("phpsqlajax_dbinfo.php");

// Start XML file, create parent node

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$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 maps_pc_markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml;charset=utf-8");
header("Encoding: ISO-8859-1");
echo '<xml http-equiv="Content-Type" content="text/html;charset=utf-8">';
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<dators ';
echo 'id="' . parseToXML($row['id']) . '" ';
echo 'name="' . utf8_encode(parseToXML($row['name'])) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . utf8_encode(parseToXML($row['type'])) . '" ';
echo 'os="' . utf8_encode(parseToXML($row['os'])) . '" ';
echo 'hdd="' . utf8_encode(parseToXML($row['hdd'])) . '" ';
echo 'ram="' . utf8_encode(parseToXML($row['ram'])) . '" ';
echo 'video="' . utf8_encode(parseToXML($row['video'])) . '" ';
echo 'email="' . utf8_encode(parseToXML($row['email'])) . '" ';
echo 'user="' . utf8_encode(parseToXML($row['user'])) . '" ';
echo 'ip="' . utf8_encode(parseToXML($row['ip'])) . '" ';
echo 'phr="' . utf8_encode(parseToXML($row['phr'])) . '" ';
echo 'comment="' . utf8_encode(parseToXML($row['comment'])) . '" ';
echo 'company="' . utf8_encode(parseToXML($row['company'])) . '" ';
echo '/>';
}
echo '</xml>';

?>


Here how my xml file looks like



<xml http-equiv="Content-Type" content="text/html;charset=utf-8">
<dators id="1" name="AM-PC-1" lat="0.000000" lng="0.000000" type="Stacion?rais" os="Windows 8.1" hdd="1TB" ram="4GB" video="Integr?ta" email="fs@fs.lv" user="KS" ip="localhost" phr="pele" comment="" company="AM"/>
<dators id="2" name="AM-PC-2" lat="2.000000" lng="2.000000" type="laptop" os="Linux" hdd="254MB" ram="2GB" video="Integreta" email="kt2@kt.lv" user="KS2" ip="" phr="pele" comment="nav" company="Ar?e"/>
</xml>

No comments:

Post a Comment