Hi everybody
my application at – http://www.maps.beechhillcommunity.org.uk/WQD/district.php
will only work for some of the records in the MySQL db (East Devon works) - on others it fails giving an XML Parsing Error -
"Warning: DOMElement::setAttribute() [domelement.setattribute]: string is not in UTF-8 in /home/beechhil/public_html/maps/WQD/title_genxml.php on line 67
Warning: DOMDocument::saveXML() [domdocument.savexml]: output conversion failed due to conv error, bytes 0x96 0x20 0x54 0x68 in /home/beechhil/public_html/maps/WQD/title_genxml.php on line 81
<marker FirstName=“Henry” LastName=“Willi…”
My code is based on the example at – http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html#outputxml
On another page http://www.maps.beechhillcommunity.org.uk/WQD/writer.php (or rather the genxml.php behind it)
I have tried to add some php to encode the $results into utf-8 but it fails…
"…
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
echo $num_rows;
// Put results in array
for($i = 0; $array[$i] = mysql_fetch_assoc($result); $i++) ;
// force utf-8 encoding
function convertArrayKeysToUtf8(array $result) {
$convertedArray = array();
foreach($array as $key => $value) {
if(!mb_check_encoding($key, ‘UTF-8’)) $key = utf8_encode($key);
if(is_array($value)) $value = $this->convertArrayKeysToUtf8($value);
$convertedArray[$key] = $value;
}
return $convertedArray;
}
convertArrayKeysToUtf8($convertedArray);
header(“Content-type: text/xml”);
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($convertedArray)){
$node = $dom->createElement(“marker”);
$newnode = $parnode->appendChild($node);
$newnode->setAttribute(“LastName”, $row[‘LastName’]);
…"
I’ve been going crazy with this, I’m new to php and coding in general and very pleased to have got this far. I just need some way to get around/over the encoding problem. Any help gratefully received
Gazza