1

我有这个代码

$doc = new DOMDocument; 
$doc->load('Clans/' . $_POST['s']);

$thedocument = $doc->documentElement;

//this gives you a list of the messages
$list = $thedocument->getElementsByTagName('member');
foreach($_POST['delete_unit'] as $unit_id){
$nodeToRemove = null;
foreach ($list as $domElement){
  $attrValue = $domElement->getAttribute('id');
  if ($attrValue == $unit_id) {
    $nodeToRemove = $domElement; //will only remember last one- but this is just an example :)
  }
}
}

//Now remove it.
if ($nodeToRemove != null)
$thedocument->removeChild($nodeToRemove);

$doc->saveXML('Clans/' . $_POST['s']);

POST['delete_unit'] 是 ids 数组为什么这不起作用或有更好的方法来做到这一点

错误代码 PHP Catchable 致命错误:传递给 DOMDocument::saveXML() 的参数 1 必须是 DOMNode 的实例,字符串在

4

1 回答 1

1

在最后一行,我想你正在寻找

file_put_contents('Clans/' . $_POST['s'], $doc->saveXML());

如果未传递任何参数,saveXML()则将完整文档作为字符串返回。

您还需要考虑清理表单输入!

于 2013-09-11T16:05:50.427 回答