日期:2014-05-17 浏览次数:20618 次
<?xml version="1.0" encoding="GB2312"?> <AppConfig> <COM>COM1</COM> <Phone>10086</Phone> <Content>测试</Content> </AppConfig>
$phone=123; $xmlDoc = new DOMDocument(); $xmlDoc->load("bb.xml"); $xml = new SimpleXMLElement($xmlDoc->saveXML()); $xml->Phone = $phone; file_put_contents('bb.xml', $xml->asXML());
------解决方案--------------------
<?php $xml = new DOMDocument("1.0","GB2312");//实例化domdocument类 $xml->load('test3.xml');//加载xml文件 $list=$xml->getElementsByTagName('Phone'); $phone='iphone'; $list->item(0)->nodeValue=$phone; $xml->save("test3.xml");//保存 ?>
------解决方案--------------------
<?php require_once("xmlparse.php"); $xml = new DOMDocument("1.0","GB2312"); $xml->load("你的xml的路径"); $list=$xml->getElementsByTagName('Phone'); $list->item(0)->nodeValue=$phone; $xml->save("你的xml的路径");//保存 ?>