0
這裏是我的代碼:PHP的XML文件追加
public function write($txt){
$randID = rand();
$doc = new DOMDocument();
$doc->formatOutput = true;
$doc->load($this->fileName);
$b = $doc->createElement("input");
$id = $doc->createElement("id",$randID);
$b->appendChild($id);
$text = $doc->createElement("text",$txt);
$b->appendChild($text);
$doc->appendChild($b);
$doc->save($this->fileName);
}
爲什麼這個代碼總是覆蓋舊的文件?爲什麼它不附加到現有文件的末尾?我是新來的XML與PHP :)
您打開'新的DomDocument()',而不是現有的['DomDocument :: load()'](http://www.php.net/manual/ru/domdocument.load.php) – J0HN
Can您在調用腳本之前給出了文件a)的示例,b)腳本完成後,c)預期的結果? – VolkerK