$dom = new DOMDocument ( ‘1.0‘, ‘gbk‘ ); $dom->formatOutput = true; $comment_str = ‘ file create time: ‘ . date(‘Y-m-d H:i:s‘, time()) . ‘ by tree.php ‘; $dom->appendChild(new DOMComment($comment_str)); $edbnode = $dom->createElement ( ‘edbnode‘ ); $edbnode = $dom->appendChild ( $edbnode ); $dom->save(‘文件路径‘,LIBXML_NOBLANKS); //也可以直接输出 echo $dom->saveXML();
原文地址:http://my.oschina.net/surjur/blog/289785