$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>
你提前打印了$name 数组当然是那个样子啦,你在外层foreach下面打印$name 就对了。
你提前打印了$name 数组当然是那个样子啦,你在外层foreach下面打印$name 就对了。
试过了 不是这个原因~~你可以看看啊 打印出的是前两行的值。。哈哈
这个意思?
$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) { if($b->attributes->getNamedItem('label')->nodeValue == 'xiao') { foreach($b->attributes as $attr){ $res[$attr->nodeName] = $attr->nodeValue; } print_r($res); }}Array