无法累加值 xml

Trouble adding up value xml

我希望在每次访问者访问页面时将 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'].'/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;