Php 添加xml值时遇到问题
我希望在每次访问者访问页面时,将XML节点增加1 这是我目前拥有的,但它不断返回值1Php 添加xml值时遇到问题,php,xml,simplexml,Php,Xml,Simplexml,我希望在每次访问者访问页面时,将XML节点增加1 这是我目前拥有的,但它不断返回值1 <?php $xPostName = $xml->up; //load xml file to edit $xml = simplexml_load_file($_GET['id'].'/info.xml'); $xml->up = $xPostName +1; // save the updated document $xml->asXML($_GET['id'].'/
<?php
$xPostName = $xml->up;
//load xml file to edit
$xml = simplexml_load_file($_GET['id'].'/info.xml');
$xml->up = $xPostName +1;
// save the updated document
$xml->asXML($_GET['id'].'/info.xml');
echo "done";
?>
问题在于,您在加载文件之前设置了
$xPostName
,因此此时没有值,然后将1添加到此值以更新值
$xPostName = $xml->up;
//load xml file to edit
$xml = simplexml_load_file($_GET['id'].'/info.xml');
$xml->up = $xPostName +1;
所以在加载文件后将其移动到
//load xml file to edit
$xml = simplexml_load_file($_GET['id'].'/info.xml');
$xPostName = $xml->up;
$xml->up = $xPostName +1;
或者直接增加值
$xml = simplexml_load_file('out.xml');
$xml->up +=1;