PHP MYSQL RSS FEED限制问题

时间:2014-10-14 06:06:51

标签: php mysql rss feed

我正在尝试将来自MYsql数据库的RSS源组合在一起。但脚本只会发布2个事件。如果LIMIT设置为3或更多,则会出现错误消息:

This page contains the following errors:
error on line 26 at column 29: xmlParseEntityRef: no name

下面是第一个错误之前的页面呈现。这是我的代码:

<?php
header('Content-Type: text/xml');
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>My Website Name</title>
<description>A description of the feed</description>
<link>The URL to the website</link>';

$get_articles = "SELECT id, title, description,
DATE_FORMAT(start_date,'%a, %e %b %Y %T') as formatted_date
FROM table_name ORDER BY start_date DESC LIMIT 4";

$articles = mysql_query($get_articles) or die(mysql_error());

while ($article = mysql_fetch_array($articles)){

echo '
   <item>
      <title>'.$article[title].'</title>
      <description><![CDATA[
      '.$article[description].'
      ]]></description>
      <link>http://www.gigreview.com.au/index.php/gig-review/'.$article[id].'</link>
      <pubDate>'.$row[formatted_date].' GMT</pubDate>
  </item>';
}
echo '</channel>
</rss>';
?>

1 个答案:

答案 0 :(得分:0)

尝试通过http://validator.w3.org/feed/验证XML - 也许它的标志就像&amp;这需要&amp; - 您可以尝试:http://php.net/manual/en/function.htmlspecialchars.php