Welsh character encoding - need help
Posted: Mon Sep 11, 2006 11:15 am
I am attempting to export the contents of a hosted MySQL database into XML using a php (4) script. However there are some unique characters that cannot be displayed and as such prevent the XML from forming such as Ó etc
Below is the code i am using:
Code:
If i remove the fields containing the dodgy characters then the XML is generated without any problems. I beleive that the problem is to do with the encoding being used but am completely unsure about syntax.
Any help is much appreciated.
Jim
Below is the code i am using:
Code:
Code: Select all
<?php
$db = mysql_connect(localhost, ************, *****);
mysql_select_db(************, $db) or die("Unable to select database");
$query = "SELECT ref, street, town, price, bull1, bull2, bull3, bull4, mphoto, photo1, photo2, photo3, photo4, status, blae, caer, llang, llanr, porth, pwll FROM res";
// Execute the query
$result = mysql_query($query) or die("Query failed");
// query database for records
$connection = mysql_connect(localhost, ***********, *****) or die ("Unable
to connect!");
mysql_select_db(*************, $connection) or die ("Unable to select database!");
$query = "SELECT ref, street, town, price, bull1, bull2, bull3, bull4, mphoto, photo1, photo2, photo3, photo4, status, blae, caer, llang, llanr, porth, pwll FROM res";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
if (mysql_num_rows($result) > 0)
{
// create DomDocument object
$doc = new_xmldoc("1.0");
// add root node
$root = $doc->add_root("properties");
// iterate through result set
while(list($ref, $street, $town, $price, $bull1, $bull2, $bull3, $bull4, $mphoto, $photo1, $photo2, $photo3, $photo4, $status, $blae, $caer) = mysql_fetch_row($result))
{
// create item node
$record = $root->new_child("res", "");
$record->set_attribute("ref", $ref);
// attach title and artist as children of item node
$record->new_child("ref2", $ref);
$record->new_child("street", $street);
$record->new_child("town", $town);
$record->new_child("price", $price);
$record->new_child("bull1", $bull1);
$record->new_child("bull2", $bull2);
$record->new_child("bull3", $bull3);
$record->new_child("bull4", $bull4);
$record->new_child("mphoto", $mphoto);
$record->new_child("photo1", $photo1);
$record->new_child("photo2", $photo2);
$record->new_child("photo3", $photo3);
$record->new_child("photo4", $photo4);
$record->new_child("status", $status);
$record->new_child("blae", $blae);
$record->new_child("caer", $caer);
}
// print the tree
echo $doc->dumpmem();
}
// close connection
mysql_close($connection);
?>If i remove the fields containing the dodgy characters then the XML is generated without any problems. I beleive that the problem is to do with the encoding being used but am completely unsure about syntax.
Any help is much appreciated.
Jim