gpt4 book ai didi

php - 第 1 列第 2 行错误 : Extra content at the end of the document

转载 作者:IT王子 更新时间:2023-10-28 23:46:47 24 4
gpt4 key购买 nike

当我使用下面的代码并在本地解析 xml 时,它可以正常工作,但是在服务器上上传相同的脚本时,它会显示错误。

注意:我从查询字符串中检索了 $lng$lat,它在本地运行良好。

$lng=$_GET['lng'];
$lat=$_GET['lat'];
$conn=new LoginSystem();
$conn->connect();
$dom = new DOMDocument("1.0");

$query="select catch_id,catch_details,image from mycatch where longitude='$lng' AND latitude='$lat'";
$result = mysql_query($query);

if (!$result) {
die("Invalid query: " . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
$node = $dom->createElement("mycatch");
$node = $dom->appendChild($node);
foreach ($row as $fieldname => $fieldvalue) {
$child = $dom->createElement($fieldname);
$child = $node->appendChild($child);
$value = $dom->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}

$conn->disconnect();
$xml_string = $dom->saveXML();
echo $xml_string;

在服务器上它会抛出此错误。而且文件也是空的.....

This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

最佳答案

我认为您正在创建一个如下所示的文档:

<mycatch>
....
</mycatch>
<mycatch>
....
</mycatch>

这不是一个有效的 XML 文档,因为它有多个根元素。您必须有一个顶级元素,如

<mydocument>      
<mycatch>
....
</mycatch>
<mycatch>
....
</mycatch>
....
</mydocument>

关于php - 第 1 列第 2 行错误 : Extra content at the end of the document,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com