我正在尝试制作一个简单的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>
答案 0 :(得分:12)
您应该输出真实的<?xml version='1.0' encoding='ISO-8859-1'?>
,而不是有权的版本。因为它有问题,因为php自己的<?
,echo
它在标题之后:
<?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>
答案 1 :(得分:0)
Firefox在标题中未获取内容类型:application/rss+xml
尽管它是正确的,formally,text/xml
似乎仍然是许多rss生成器和浏览器的标准
尝试将标题更改为
header('Content-Type: text/xml; charset=utf-8');