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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器