array(
name => text,
surname => text,
country => text,
date => text
)
1) How can I save this array to file as xml file?
// save
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
foreach($arr as $key=>$value)
{
$em = $doc->createElement($key);
$text = $doc->createTextNode($value);
$em->appendChild($text);
$root->appendChild($em);
}
$doc->save('file.xml');
// load
$arr = array();
$doc = new DOMDocument();
$doc->load('file.xml');
$root = $doc->getElementsByTagName('root')->items[0];
foreach($root->childNodes as $item)
{
$arr[$item->nodeName] = $item->nodeValue;
}