简单的 RSS 提要
Posted
技术标签:
【中文标题】简单的 RSS 提要【英文标题】:simple rss feed 【发布时间】:2011-04-08 04:37:00 【问题描述】:我正在尝试制作一个简单的 rss 提要,但问题是当我运行文件时说你想打开 rss.php ...
这里的代码可能是我做错了什么?我把它放在这种格式只是为了看看它的工作原理。
<?php
header('Content-Type: application/rss+xml; charset=utf-8');
?>
<?xml version='1.0' encoding='ISO-8859-1'?>
<rss version='2.0'>
<channel>
<title>feed title</title>
<description>this is my example</description>
<link>http://localhost:8888/redline</link>
<copyright>Copyright (C) 2010 sarmenhb</copyright>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
</channel>
</rss>
【问题讨论】:
【参考方案1】:你应该输出真实的<?xml version='1.0' encoding='ISO-8859-1'?>
,而不是实体化的版本。既然是php自带的<?
,echo
就在header后面有问题:
<?php
//header('Content-Type: application/xml');
header('Content-Type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<rss version='2.0'>
<channel>
<title>feed title</title>
<description>this is my example</description>
<link>http://localhost:8888/redline</link>
<copyright>Copyright (C) 2010 sarmenhb</copyright>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
<item>
<title>Example 1</title>
<description>This is the description of the first example.</description>
<link>http://www.example.com/example1.html</link>
<pubDate>Mon, 29 Dec 2008 22:10:00 -0600</pubDate>
</item>
</channel>
</rss>
【讨论】:
我需要在刚买的这台 MacBook 上磨练我的打字速度。 +1【参考方案2】:Firefox 没有在标头中获取内容类型:application/rss+xml
虽然是正确的,formally、text/xml
似乎仍然是相当多的 rss 生成器和浏览器的标准
尝试将标题更改为
header('Content-Type: text/xml; charset=utf-8');
【讨论】:
以上是关于简单的 RSS 提要的主要内容,如果未能解决你的问题,请参考以下文章
是否可以从 restservice java 消费 rss 提要?