Php xml文件中附加了不正确的元素
我的服务器上运行着一个xml文件。虽然在我的localserver中一切正常,但当我将它上载到我的服务器上时,当许多人都在使用它时,我的xml文件中出现了一个错误 我在php中使用simplexml来读取和更新数据 比如说,, 我的xml文件的结构如下Php xml文件中附加了不正确的元素,php,xml,Php,Xml,我的服务器上运行着一个xml文件。虽然在我的localserver中一切正常,但当我将它上载到我的服务器上时,当许多人都在使用它时,我的xml文件中出现了一个错误 我在php中使用simplexml来读取和更新数据 比如说,, 我的xml文件的结构如下 <?xml version="1.0"?> <db> <uid></uid> <score></score> </db> 这就是我关闭它的方式- file_pu
<?xml version="1.0"?>
<db>
<uid></uid>
<score></score>
</db>
这就是我关闭它的方式-
file_put_contents($file, $data->asXML(), LOCK_EX);
它在我的本地服务器上运行得很好。当我把它上传到网上时,它可以正常工作一段时间,但是突然间,奇怪的事情发生在我的xml文件上。怎么了
编辑:
我的更新代码-
<?php
include('functions.php');
$winid= $_GET['wid'];
$loseid=$_GET['lid'];
$winid=intval($winid);
$loseid=intval($loseid);
$file="data.xml";
$data= new SimpleXMLElement($file, null, true);
$winner=intval($data->score[$winid]);
$loser=intval($data->score[$loseid]);
$exp_winner=expected($loser,$winner);
$new_win=win($winner,$exp_winner);
$exp_loser=expected($winner,$loser);
$new_lose=loss($loser,$exp_loser);
$data->score[$winid]=$new_win;
$data->score[$loseid]==$new_lose;
file_put_contents($file, $data->asXML(), LOCK_EX);
header("Location: index.php");
?>
尝试将所有出现的
$data->score['string']
更改为$data->score->string
。看看是否有帮助
示例:更改$winner=intval($data->score[$winid])代码>到$winner=intval($data->score->$winid)代码>
另外,您在这一行中意外地写了两个等号$data->score[$loseid]==$new\u lose代码> LOCK_EX
是在5.1中添加的,您是否在主机服务器上至少使用此版本?请务必尝试phpinfo()
。我检查了PHP版本。它是-PHP版本5.3.14好的下一个问题,您如何知道它在本地服务器上工作?您是否有许多用户像在托管服务器上一样同时点击它?如果没有,那么您还没有真正确认它在本地有效。它不能直接帮助您解决问题,但至少如果您可以在本地复制它,那么您调试它时的痛苦会小得多。这非常奇怪,因为文件内容会覆盖您的文件,因此更新数据时一定出了问题!你能告诉我们你是怎么做到的吗?@leftclickben你是对的,我不能确认它在本地工作。但我不能让很多用户在本地点击它。我一个人工作,我试过这个。它不起作用。事实上,它创建了我不想要的额外分数标签。
<db>
<uid></uid>
<core></score>
</db>
$data= new SimpleXMLElement($file, null, true);
file_put_contents($file, $data->asXML(), LOCK_EX);
<?php
include('functions.php');
$winid= $_GET['wid'];
$loseid=$_GET['lid'];
$winid=intval($winid);
$loseid=intval($loseid);
$file="data.xml";
$data= new SimpleXMLElement($file, null, true);
$winner=intval($data->score[$winid]);
$loser=intval($data->score[$loseid]);
$exp_winner=expected($loser,$winner);
$new_win=win($winner,$exp_winner);
$exp_loser=expected($winner,$loser);
$new_lose=loss($loser,$exp_loser);
$data->score[$winid]=$new_win;
$data->score[$loseid]==$new_lose;
file_put_contents($file, $data->asXML(), LOCK_EX);
header("Location: index.php");
?>