【问题标题】:SimpleXMLElement Object back to XML with greek charachers (UTF-8 encoding)SimpleXMLElement 对象返回到带有希腊字符的 XML(UTF-8 编码)
【发布时间】:2022-07-06 18:45:05
【问题描述】:

我有一个使用 simplexml 导入的 XML,然后对其进行编辑并将其返回到一个新文件。 但是希腊字符正在被摧毁(逃脱?) 如何将其强制为 UTF-8? 旧文件在 xml 标签中有 encoding="UTF-8",新文件没有。

$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');

【问题讨论】:

标签: php xml simplexml


【解决方案1】:

在'new DOMDocument'中,如果我们将'UTF-8'作为第二个参数添加,它会得到它作为编码,并且可以工作

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 2011-02-21
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多