I have some problems with decoding XML, I have the following XML:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<advastamedia xmlns="http://www.advasta.com/XMLSchema/5.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.advasta.com/XMLSchema/5.02 http://www.advasta.com/XMLSchema/5.02.30/advastamedia502.xsd" created="2011-04-27T11:48:50.000+01:00" version="5.02" language="de-DE" decimalseparator="," groupseparator=".">
<-- skipped a part here -->
<textvalue pos="1">
<data>Exklusiv bei Mein – „ES“ Griffdesign für komfortables Aufhängen des Werkzeugs</data>
</textvalue>
<textvalue pos="7">
<data>Große Gras- und Strauchscherenklingen</data>
</textvalue>
Code: Select all
// start importing
$xml_import = simplexml_load_file($sFileName);
$namespaces = array_merge(array('' => ''), $xml_import->getDocNamespaces(true));
$myArray = array();
$myArray = xml2phpArray($xml_import, $namespaces, $myArray);
echo "<pre>";
var_dump($myArray);
echo "</pre>";
// xml2phpArray function
// converts xml 2 php array
function xml2phpArray($xml, $namespaces, $arr) {
$iter = 0;
foreach ($namespaces as $namespace => $namespaceUrl) {
foreach ($xml->children($namespaceUrl) as $b) {
$a = $b->getName();
if ($b->children($namespaceUrl)) {
$arr[$a][$iter] = array();
$arr[$a][$iter] = xml2phpArray($b, $namespaces, $arr[$a][$iter]);
}
else {
$arr[$a] = trim($b[0]);
}
$iter++;
}
}
return $arr;
}
Exklusiv bei Mein – „ES“ Griffdesign für komfortables Aufhängen des Werkzeugs
Große Gras- und Strauchscherenklingen
as you can see, all special characters are looking weird.
If I change this line of code in PHP from:
Code: Select all
$arr[$a] = trim($b[0]);Code: Select all
$arr[$a] = trim(utf8_decode($b[0]));Exklusiv bei Mein ? ?ES? Griffdesign für komfortables Aufhängen des Werkzeugs
Große Gras- und Strauchscherenklingen
how can I fix this, that ALL special characters are being shown properly ?
thanks for your help!