动态站点地图显示错误 php xmlParseEntityRef:无名称

dynamic sitemap showing error php xmlParseEntityRef: no name

我正在制作动态站点地图并收到此错误,但我不明白问题出在哪里。请指导。我知道一些答案已经存在

 error on line 87 at column 64: xmlParseEntityRef: no name

这是代码

<?php
    require_once("configure/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;
    ?>

您需要将 & 替换为 &amp;:

echo '<loc>'.'localhost:8080/mysite/admitcard/'.$row2["id"].'/'.str_replace(' ','-',trim(preg_replace('/&(?!#?[a-z0-9]+;)/', '&amp;', $row2['pagename_admit']))).'</loc>' . PHP_EOL;