Hello.
I'm working with a webpage where its going to a Google Store Locator.
Goolge Store Locator guide I did follow. I got it working for a while, but here in Norway we have some characters, ÆØÅ that we use. This is the problem. When I search for a place, which contains the letters ÆØÅ the XML generated an error in the error_log file.

[14-Feb-2011 14:43:46] PHP Warning: DOMDocument::saveXML() [<a href='domdocument.savexml'>domdocument.savexml</a>]: output conversion failed due to conv error, bytes 0xF8 0x72 0x65 0x20 in /home/vaskepla/public_html/test/phpsqlsearch_genxml.php on line 53

<?php  
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];

// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

mysql_set_charset('utf-8',$connection);

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}

// Search the rows in the markers table
$query_set = mysql_query("SET address, name 'utf8'");
$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($center_lng),
  mysql_real_escape_string($center_lat),
  mysql_real_escape_string($radius));
$result = mysql_query($query);

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}
header("Content-type: text/html; charset=UTF-8");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("name", $row['name']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("lat", $row['lat']);
  $newnode->setAttribute("lng", $row['lng']);
}

echo $dom->saveXML();
?>

Are there something I should do with the MySQL database or the Tables. They are in UTF-8 general charset.

Does anyone know anything about this?

Recommended Answers

All 3 Replies

Sometimes I fear that for all the good reasons to use UTF-8, it has thrown us developers back into the times of ASCII/ANSI incompatibilities.

Make sure that *all* your connections use UTF-8. Use

mysql_set_charset( "utf8", $connection );
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $cconnection);

bytes 0xF8 0x72 0x65 0x20 are not properly encoded UTF-8. Obviously they don't get converted on their way from the database to the XML file. Are you sure that their binary representation in the database is UTF? How did they get in the database?
MySQL's character set property can be misleading. MySQL does not automagically do character set conversions - only if client and server are announcing to use different character sets a conversion takes place. It's quite easy to be fooled to believe that your data are stored in UTF because the table or the field is defined using that character set. But if your store invalid UTF data in such a field, they stay invalid.

Thanks for your help!

Maybe you can help me with some thing else to;
I have to get data from the field "tlf" from the same table in the same mysql database. How to get that to the marker? Have any idea?

Are these text data which you want to display in a google map? The only mechanism I know of is the HTML code which can be assigned to each marker and which opens on mouse-over. But it's too long since I did that. - You will have to generate some javascript code in your PHP which contains the tlf content and then use the google map API.
Here a snippet from another project of mine where an XML file containing locations has been read and now the locations are set on the google map with some html code in the overlay window.

function addOnlyOneMarker(location) {
	var myPoint = new GLatLng( location.latitude.value, ocation.longitude.value);
	var myMarker = new GMarker(myPoint);	  	
	map.addOverlay(myMarker);
  	var msg = location.name.value 
		+ '<br/>' + location.street.value
		+ '<br/>' + location.zipcode.value
		+ ' ' + location.town.value
		+ '<br/>' + location.phone1.value;
	myMarker.setImage(IMAGE_green);
	myMarker.bindInfoWindow(msg, {onOpenFn: infowindowopen } );
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.