我有一个长这样的XML文件。
<table id="0">
</table>
<table id="1">
</table>
<table id="2">
</table>
我想检查一个id为x的表是否存在。
我一直在尝试这个,但不起作用。
$file=fopen("config.xml","a+");
while (!feof($file))
{
if(fgets($file). "<br>" === '<table id="0">'){
echo fgets($file). "<br>";
}
}
fclose($file);
'a+'
来打开文件?'a'
表示追加,因此它将指针放在文件末尾。请尝试使用$file=fopen("config.xml","r");
。 - gen_Ericr+
。这样你就可以从开头读取,然后将其移动到稍后想要写入的位置。 - gen_Eric