I have a problem, which makes me go crazy 2 days, I have an associative array in php that contains multiple sub tables, I want to turn it into xml and especially simplexml, but I think I have a problem with everything accent special character, etc. they told me to change the encoding "ISO-8859-1", but it does not work, can you help me.`
<?php
header('Content-type: text/html');
$xml_student_info = new SimpleXMLElement('<?xml version="1.0" encoding="ISO-8859-1" ?>');
// function defination to convert array to xml
function array_to_xml($student_info, $xml_student_info) {
foreach($student_info as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_student_info->addChild("$key");
array_to_xml($value, $subnode);
}
else{
array_to_xml($value, $xml_student_info);
}
}
else {
$xml_student_info->addChild($key,$value);
}
}
return $xml_student_info; }
//function call to convert array to xml
echo array_to_xml($wall,$xml_student_info)->asXML();
exit( ) ;
?>
Et voici la réponse:
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\Program Files (x86)\EasyPHP-5.3.9\www\fbcnx.php on line 4
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ?> in C:\Program Files (x86)\EasyPHP-5.3.9\www\fbcnx.php on line 4
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in C:\Program Files (x86)\EasyPHP-5.3.9\www\fbcnx.php on line 4
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\Program Files (x86)\EasyPHP-5.3.9\www\fbcnx.php:4 Stack trace: #0 C:\Program Files (x86)\EasyPHP-5.3.9\www\fbcnx.php(4): SimpleXMLElement->__construct('