php - 无法添加值 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;
推荐阅读
- linux - 在 Microsoft Windows Server 2016 标准版中安装 TMUX 和 MSYS2 问题
- routes - SwiftUI中如何动态路由到任意页面,我需要从通用链接跳转到对应页面
- bluetooth - 用于实现现代电视遥控功能的最常见蓝牙配置文件
- arrays - C将数组视为指针
- android - 为什么预览窗口显示不同的屏幕和真实设备不同?
- javascript - 使用来自不同文件的按钮更改反应状态
- javascript - 使用 react.State 将数据从父级传递给子级,但状态重置为初始状态
- java - Instagram 应用程序无法使用 Android Intent 打开
- python - 如何使用 GroupBy 函数来匹配 Year 和 Country?
- sql - SQL 中的数据透视和计数