【问题标题】:Creating XML sitemap getting error [duplicate]创建 XML 站点地图出现错误 [重复]
【发布时间】:2019-01-18 19:08:12
【问题描述】:

我正在尝试为我的 php 脚本创建站点地图,我的代码是:

$base_url = "https://www.mywebsite.com/index.php?a=browse&b=category&id=";

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;

while($row = mysqli_fetch_array($result))
{
 echo '<url>' . PHP_EOL;
 echo '<loc>'.$base_url. $row['category_id'] .'</loc>' . PHP_EOL;
 echo '<changefreq>daily</changefreq>' . PHP_EOL;
 echo '</url>' . PHP_EOL;
}

我收到此错误:

【问题讨论】:

  • 验证者在=符号处抱怨。也许尝试使用 [CDATA] 块?

标签: php xml xml-parsing syntax-error sitemap


【解决方案1】:

谢谢! 奈杰尔·任..

我只替换了这一行,它起作用了:

$base_url = "https://www.mywebsite.com/index.php?a=browse&b=category&id=";

到

$base_url = "https://www.mywebsite.com/index.php?a=browse&amp;b=category&amp;id=";

【讨论】:

    猜你喜欢
    • 2011-08-06
    • 2015-06-24
    • 2011-02-14
    • 2019-06-10
    • 2019-06-22
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多