使用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>
");
答
Are you sure that $a['post'] contains the post?
Missing quotes for array index in $a[perm_link];
The variable you store the date in is called $date, while in the feed you're putting $date2;
(does not compromise the functionalities but) why did you declare that $ch var just before the loop?