我曾经在我的网站上有一个很好的工作 XML 文件(谷歌地图的来源)。直到几天前才得到这个错误:
此页面包含以下错误:第 2 行第 10896 列的错误:EntityRef:期待 ';' 下面是第一个错误之前的页面渲染。
在那个时间段内,我没有对 php 文件进行更改。还做了一些数据库检查,一切似乎都井井有条(数据库连接工作正常)。
我读到一个常见的原因是使用&而不是&。但是在其中parseToXML
有一个替换功能,所以这不是我想的原因。
有小费吗?
谢谢!
标记
require("credentials.php");
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, name, address, lat, lng, descrip FROM people";
$result = $conn->query($sql);
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
$ind=0;
// Iterate through the rows, printing XML nodes for each
while($row = $result->fetch_assoc()) {
// Add to XML document node
echo '<marker ';
echo 'id="' . $row['id'] . '" ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'descrip="' . $row['descrip'] . '" ';
echo '/>';
$ind = $ind + 1;
}
// End XML file
echo '</markers>';