dpsyssiv90846 2010-12-21 07:51
浏览 57
已采纳

使用PHP创建的RSS提要仅在提要阅读器中显示标题

I am using the following PHP code to generate the XML for an RSS feed, but it doesn't seem to be working correctly. No short description is displayed in the feed reader, all I see is the title of the article. Also, all of the articles say they were published at the same time. This is the first time I have tried to setup an RSS feed, so I'm sure I've made several stupid mistakes.

$result = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT 10");

$date = date(DATE_RFC822);

header('Content-type: text/xml');

echo ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
");
echo ("<rss version=\"2.0\">
");
echo ("<channel>
");
echo ("<lastBuildDate>$date</lastBuildDate>
");
echo ("<pubDate>$date</pubDate>
");
echo ("<title>my website name</title>
");
echo ("<description><![CDATA[the description]]></description>
");
echo ("<link>http://my-domain.com</link>
");
echo ("<language>en</language>
");

$ch=100;
while ($a = mysql_fetch_array($result)) {
    $headline = htmlentities(stripslashes($a['subject']));
    $posturl = $a[perm_link];
    $content = $a['post'];
    $date = date(DATE_RFC822, $a['posted']);

    echo ("<item>
");
    echo ("<title>$headline</title>
");
    echo ("<link>$posturl</link>
");
    echo ("<description><![CDATA[$content]]></description>
");
    echo ("<guid isPermaLink=\"true\">$posturl</guid>
");
    echo ("<pubDate>$date2</pubDate>
");
    echo ("</item>
");
}

echo ("</channel>
");
echo ("</rss>
");
  • 写回答

1条回答 默认 最新

  • doushi7761 2010-12-21 08:24
    关注
    1. Are you sure that $a['post'] contains the post?

    2. Missing quotes for array index in $a[perm_link];

    3. The variable you store the date in is called $date, while in the feed you're putting $date2;

    4. (does not compromise the functionalities but) why did you declare that $ch var just before the loop?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划