我是PHP和XML的初學者。在PHP中包含XML編碼
有人可以告訴我如何在編寫新的xml文件時包含XML編碼。
這裏是代碼:
writexml.php
<?php
$ids = array("1", "2", "3", "4", "5");
$names = array("Jean Claude Van Damme", "Scott Adkins", "Dolph Ludgren", "Michael Jai White", "Michael Worth");
$domdoc = new DOMDocument();
$domdoc->formatOutput = true;
$el_actionstars = $domdoc->createElement("actionstars");
$domdoc->appendChild($el_actionstars );
$arr_size = count($ids);
for ($i=0; $i < $arr_size; $i++) {
$el_actionstar = $domdoc->createElement("actionstar");
$el_id = $domdoc->createElement("id");
$el_id->appendChild($domdoc->createTextNode($ids[$i] . ""));
$el_actionstar->appendChild($el_id);
$el_name = $domdoc->createElement("name");
$el_name->appendChild($domdoc->createTextNode($names[$i] . ""));
$el_actionstar->appendChild($el_name);
$el_actionstars->appendChild($el_actionstar);
}
echo $domdoc->saveXML();
$domdoc->save("actionstars.xml")
?>
XML輸出是<?xml version="1.0"?>
,我想補充的編碼使它看起來像<?xml version="1.0" encoding="ISO-8859-1"?>
。請幫助...
[複製](http://stackoverflow.com/questions/869650/getting-simplexmlelement-to-include-the-encoding-in-output) – 2011-05-31 07:07:20
爲[DOM文檔:: __構建體的例子](http://de3.php.net/manual/en/domdocument.construct.php)顯示瞭如何做到這一點。在提出明顯的答案之前,請參閱手冊。 – Gordon 2011-05-31 07:16:45
大聲笑。有人注入更多的愛... – tofutim 2011-05-31 07:19:36