新手发个php修改XML的问题!!
$dom=new DOMDocument('1.0');
$dom->load('ceshi.xml');
$root=$dom->getElementsByTagName('online');
$root=$root->item(0);
$userid=$root->getElementsByTagName('userid');
foreach($userid as $b)
{
foreach($b->attributes as $attr){
$value=$attr->nodeValue;
$name[].=$attr->nodeName;
{if($value=="xiao")
{
print_r($name);
}
}
}
}
$dom->save('ceshi.xml');
<?xml version="1.0"?>
<online>
<userid time="2007-06-13 11:20:08" ip="wangqile" label="wang">xiaxin</userid>
<userid time="2007-06-13 13:22:15" pp="dasdsa" label="xiao" ip="dasdsa">rwet</userid>
<userid time="2007-06-13 17:17:00" ip="dasdsa" label="ji"> gaoji</userid>
</online>
$dom=new DOMDocument('1.0');Array
$dom->load('ceshi.xml');
$root=$dom->getElementsByTagName('online');
$root=$root->item(0);
$userid=$root->getElementsByTagName('userid');
foreach($userid as $b) {
if($b->attributes->getNamedItem('label')->nodeValue == 'xiao') {
foreach($b->attributes as $attr){
$res[$attr->nodeName] = $attr->nodeValue;
}
print_r($res);
}
}