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