Home > database >  SimpleXMLElement Object back to XML with greek charachers (UTF-8 encoding)
SimpleXMLElement Object back to XML with greek charachers (UTF-8 encoding)

Time:07-09

i have an XML which i import with simplexml, then edit and returning it back to a new file. But the greek characters are being destroyed (escaped?) How to force it as UTF-8? Old file has encoding="UTF-8" in xml tag, new file not.

$xml=simplexml_load_file("test.xml", 'SimpleXMLElement', LIBXML_NOCDATA);
...
$dom_sxe = dom_import_simplexml($xml);
$dom = new DOMDocument('1.0');
$dom->formatOutput = true;
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);

$dom->save('output.xml');

CodePudding user response:

In 'new DOMDocument', if we add as second parameter the 'UTF-8', it gets it as encoding, and works

$dom = new DOMDocument('1.0', 'UTF-8');
  • Related