我的方案是首先我在localhost中运行它,xml工作正常。但是当我将它上传到域名时。该页面不再显示xml,它只显示一个空白页面。但是当我试图检查它时,xml中有数据,但它也是一个嵌套的xml。这是我的代码。
<?php
require("config.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;
}
// Opens a connection to a MySQL server
$connection=mysqli_connect($databaseHost, $databaseUsername, $databasePassword);
if (!$connection) {
die('Not connected : ' . mysqli_error());
}
// Set the active MySQL database
$db_selected = mysqli_select_db($connection, $databaseName);
if (!$db_selected) {
die ('Can\'t use db : ' . mysqli_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysqli_query($connection, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error($connection));
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo "<?xml version='1.0' ?>";
echo '<markers>';
$ind=0;
// Iterate through the rows, printing XML nodes for each
while ($row = @mysqli_fetch_assoc($result)){
// Add to XML document node
echo '<marker ';
echo 'id="' . $row['id'] . '" ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'contact_number="' . parseToXML($row['contact_number']) . '" ';
echo 'contact_number1="' . parseToXML($row['contact_number1']) . '" ';
echo 'contact_number2="' . parseToXML($row['contact_number2']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'image="' . $row['image'] . '" ';
echo '/>';
$ind = $ind + 1;
}
// End XML file
echo '</markers>';
?>
我使用了在我的localhost和域中运行的相同代码,但在域中没有任何内容。
答案 0 :(得分:0)
我发现我的域名和本地的php版本不一样。我在我的域名中更改了php版本,它已经可以使用了!