douken0530 2011-08-04 09:24
浏览 110
已采纳

RSS Feed不起作用:<?xml version =“1.0”encoding =“iso-8859-1”?>

I've been writing a simple PHP script which is supposed to generate a RSS Feed extracting data from a MySQL database.

<?php
require("$_SERVER[DOCUMENT_ROOT]mysql.php");
$type = $_GET["type"];
$result = mysql_query("SELECT * FROM Setting WHERE Type = \"$type\"");
header("Content-Type: text/xml");
echo "
<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<rss version=\"2.0\">
  <channel>
    <title>Vhannibal &ndash; I migliori setting per Dreambox! &ndash; Feed RSS</title>
    <link>http://www.vhannibal.net/</link>
    <description>".$type."</description>
";
while ($row = mysql_fetch_array($result))
{
    extract($row);
    echo "
    <item>
      <title>$row[Name]</title>
      <link>http://www.vhannibal.net/download_setting.php?id=$row[ID]</link>
      <description>".strftime("%e %b", $row["Date"])."</description>
    </item>
  </channel>
</rss>
";
}
?>

The problem is <?xml version="1.0" encoding="iso-8859-1"?> comes after an unwanted empty line generated by the PHP script which I think is the reason why it doesn't work. Am I right? How can I solve it? Thanks.

  • 写回答

1条回答 默认 最新

  • dongne1560 2011-08-04 09:30
    关注

    Your problem is the &ndash; entity in the title element which is not valid in xml (it's an html defined entity); just use "-" or use the decimal version: &#8210;.

    Also, you need to put the channel and rss end tags outside of the while cycle.

    To get rid of the first blank line, just replace

       echo "
        <?xml version="1.0" encoding="iso-8859-1"?>
        [...]
    

    with

       echo "<?xml version="1.0" encoding="iso-8859-1"?>
       [...]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分