加一个到xml节点的值
这个问题在这里已经有了答案:
尝试这样的事情:
$objectX = "2"; // You get this value with $_POST or $_GET ...
$xmlFileName = 'my.xml'; // You're XML file
$xmlFile = file_get_contents($xmlFileName); // Saving the XML contents in a variable
$objects = new SimpleXMLElement($xmlFile);
$objectX = "object".$objectX; // The object name
$objects->$objectX->value++; // Incrementing the value
$objects->asXML($xmlFileName); // Saving the XML
echo $objects->$objectX->value; // echo the value
您必须将<objects></objects>
到您的XML文件中:
<?xml version="1.0" encoding="UTF-8"?>
<objects>
<object1>
<value>10</value>
</object1>
<object2>
<value>6</value>
</object2>
</objects>
链接地址: http://www.djcxy.com/p/29835.html