xml文件中添加了不正确的元素


Incorrect elements appended in xml file

我有一个xml文件在我的服务器上运行。虽然在我的本地服务器上一切都很好,但是当我把它上传到我的服务器上时,当很多人使用它时,我在我的xml文件中得到一个错误。

我使用simplexml在php读取和更新数据。

例如,

我的xml文件

的结构如下
<?xml version="1.0"?>
<db>
<uid></uid>
<score></score>
</db>

虽然它完美地工作了一段时间,但一段时间后,一些元素被追加到我的xml文件。例如,

<db>
<uid></uid>
<score></score>
</db>/score</db>

<db>
<uid></uid>
<score><//score>
</db>

<db>
<uid></uid>
<core></score>
</db>

然后我得到解析错误。是因为很多人同时在写我的xml文件吗?我正在使用LOCK_EX,所以这不应该是一个问题

这是我打开它的方式-

$data= new SimpleXMLElement($file, null, true);

我是这样关闭它的-

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_lose; !