首页 > 解决方案 > 在动态站点地图 php xml xmlParseEntityRef 中显示错误:没有名称

问题描述

我正在制作动态站点地图,但出现以下错误,我知道答案已经存在但我不明白,请指导

error on line 68 at column 69: xmlParseEntityRef: no name

这是代码有什么问题

<?php
require_once("config.php");

$status=1;
$sql1 = "SELECT * FROM admitcard  WHERE status=? ORDER BY id DESC";
$stmt1 = $mysqli->prepare($sql1); 
$stmt1->bind_param("s", $status);
$stmt1->execute();
$admit_result = $stmt1->get_result();

?>
<?php

header("Content-Type: application/xml; charset=utf-8");

echo '<!--?xml version="1.0" encoding="UTF-8"?-->'.PHP_EOL; 

echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;
echo '<url>' . PHP_EOL;
echo '<loc>'.$base_url.'</loc>' . PHP_EOL;
echo '<changefreq>daily</changefreq>' . PHP_EOL;
echo '</url>' . PHP_EOL;

  while($row2=mysqli_fetch_array($admit_result)){
      echo '<url>' . PHP_EOL;
      echo '<loc>'.'localhost:8080/mysite/admitcard/'.$row2["id"].'/'.str_replace('','-',trim($row2['pagename_admit'])).'</loc>' . PHP_EOL;
      echo '<lastmod>'.date('c',time()).'</lastmod>' . PHP_EOL;
      echo '<changefreq>daily</changefreq>' . PHP_EOL;
      echo '</url>' . PHP_EOL;
     }

   echo '</urlset>' . PHP_EOL;
?>

这个运行得很完美,但是上面的脚本中显示了错误,认为它们都非常相似

while($row3=mysqli_fetch_array($schlar_result)){

    echo '<url>' . PHP_EOL;
    echo '<loc>'.'https://loclhost:8080/Site/other/'.$row3["id"].'/'. str_replace(' ','-',trim($row3['pagename_schlr'])).'</loc>' . PHP_EOL;
    echo '<lastmod>'.date('c',time()).'</lastmod>' . PHP_EOL;
    echo '<changefreq>daily</changefreq>' . PHP_EOL;
    echo '</url>' . PHP_EOL;
  }

标签: phpmysqlxmlsitemap

解决方案


推荐阅读