這裏是代碼:PHP的XML如何輸出漂亮的格式
$doc = new DomDocument('1.0');
// create root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
$signed_values = array('a' => 'eee', 'b' => 'sd', 'c' => 'df');
// process one row at a time
foreach ($signed_values as $key => $val) {
// add node for each row
$occ = $doc->createElement('error');
$occ = $root->appendChild($occ);
// add a child node for each field
foreach ($signed_values as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
// get completed xml document
$xml_string = $doc->saveXML() ;
echo $xml_string;
如果我在瀏覽器中打印我沒有得到很好的XML結構像
<xml> \n tab <child> etc.
我只是得到
<xml><child>ee</child></xml>
而且我想成爲utf-8 這是怎麼回事?
關於您的UTF-8的問題,只是把它添加到對象,比如'$ DOC =新的DOM文檔( 「1.0」, 「UTF-8」)第二參數;' – Thielicious 2016-08-23 17:59:56