51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> 其它 >> 文章正文

php制作可订阅的rss

更新时间:2012-1-10:  来源:51代码网

我想用php制作一个可订阅的rss,可是xml的格式拼成了却不能订阅,很是郁闷。希望有朋友能帮解决一下,谢谢!

拼成xml格式文件的php代码如下,也就是testkk.php的内容:

<?
$conn = mysql_connect('localhost', 'admin', 'admin');
$db_list = mysql_list_dbs($conn);
mysql_select_db('db_dawei');
$exec="SELECT  `subject` ,  `url`  FROM  `phpup_groups` WHERE  `ispassed` =1";
mysql_query("set names 'gb2312'");
$result=mysql_query($exec);

$xmlcode = '<?xml version="1.0" encoding="UTF-8"?>  
<rss version="2.0">  
<channel>
<title>14街信息订阅</title>
<link>www.14.com</link>
<description>描述</description>';


while ($arr = mysql_fetch_array($result)){

    $title = iconv("GB2312","UTF-8",$arr["subject"]);
    $link =  iconv("GB2312","UTF-8",$arr["url"]);

    $xmlcode .= "<item><title>".$title."</title><link>".$link."</link><description><![CDATA[]]></description></item>";
}
mysql_close($conn);

$xmlcode .= "</channel></rss>";

echo $xmlcode;

?>

以下是RSS 2.0的代码样例
  <!-- XML版本和字符集 -->
  <?xml version="1.0"?>
  <!-- RSS版本 -->
  <rss version="2.0">
  <!-- 以下为频道信息及新闻列表 -->
  <channel>
  <!-- 频道总体信息:开始 -->
  <!-- 频道标题 -->
  <title>Lift Off News</title>
  <!-- 频道链接的总地址 -->
  <link>http://www.751com.cn/</link>
  <!-- 频道描述文字 -->
  <description>Liftoff to Space Exploration.</description>
  <!-- 频道使用的语言(zh-cn表示简体中文) -->
  <language>en-us</language>
  <!-- 频道发布的时间 -->
  <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
  <!-- 频道最后更新的时间-->
  <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
  <docs>http://www.751com.cn/tech/rss</docs>
  <!-- 频道生成器 -->
  <generator>Weblog Editor 2.0</generator>
  <managingEditor>editor@751com.cn</managingEditor>
  <webMaster>webmaster@751com.cn</webMaster>
  <ttl>5</ttl>
  <!-- 频道总体信息:结束 -->
  <!-- 每条RSS新闻信息都包含在item节点中, -->
  <item>
  <!-- 新闻标题 -->
  <title>Star City</title>
  <!-- 新闻链接地址 -->
  <link>http://www.751com.cn/news/2003/news-starcity.asp</link>
  <!-- 新闻内容简要描述 -->
  <description>How do Americans get ready to work with Russians aboard the
  International Space Station? They take a crash course in culture, language
  and protocol at Russia's Star City.</description>
  <!-- 新闻发布时间 -->
  <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>
  <!-- 新闻目录 -->
  <category>IT</category>
  <!-- 新闻作者 -->
  <author>bill</author>
  <guid>http://www.751com.cn/2003/06/03.html#item573</guid>
  </item>
  <item>
  <title>Space Exploration</title>
  <link>http://www.751com.cn/</link>
  <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada
  will experience a partial eclipse of the Sun on Saturday, May 31st.</description>
  Fri, 30 May 2003 11:06:42 GMT</pubDate>
  <guid>http://www.751com.cn/2003/05/30.html#item572</guid>
  </item>
  <item>
  <title>The Engine That Does More</title>
  <link>http://www.751com.cn/news/2003/news-VASIMR.asp</link>
  <description>Before man travels to Mars, NASA hopes to design new engines
  that will let us fly through the Solar System more quickly. The proposed
  VASIMR engine would do that.</description>
  Tue, 27 May 2003 08:37:32 GMT</pubDate>
  <guid>http://www.751com.cn/rss.xml</guid>
  </item>
  <item>
  <title>Astronauts' Dirty Laundry</title>
  <link>http://www.751com.cn/news/2003/news-laundry.asp</link>
  <description>Compared to earlier spacecraft, the International Space
  Station has many luxuries, but laundry facilities are not one of them.
  Instead, astronauts have other options.</description>
  Tue, 20 May 2003 08:56:02 GMT</pubDate>
  <guid>http://www.751com.cn/2003/05/20.html#item570</guid>
  </item>
  </channel>
  </rss>

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |