php - 简单的 RSS 提要

标签 php xml rss

我正在尝试制作一个简单的 rss 提要,但问题是当我运行文件时说你想打开 rss.php ...

这是代码,也许我做错了什么?我把它放在这种格式中只是为了看看它是否有效。

<?php
header('Content-Type: application/rss+xml; charset=utf-8');
?>
&#60;?xml version='1.0' encoding='ISO-8859-1'?&#62;
<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>

最佳答案

你应该输出真实的<?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>

关于php - 简单的 RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3641767/

相关文章:

php - PDOStatement 对象的 var_dump 没有显示返回的数据

javascript - 如何将包含各种元素的 JSON 数组传递给 http 负载?

c# - 聚合 RSS 阅读器因 XML 无效而失败?

c# - 如何在网页中显示我的 Wordpress 站点的最新博客条目?

PHP - 自定义二维码?

php - 如何将 PhoneGap 应用程序连接到我的托管网站中的数据库?

php - 在我的情况下如何组合多个查询(选择语句)?

xml - XQuery 是否有 FLWOR 表达式的退出语句

XML 架构 : how to have multiple identical elements?

php - 在网站上显示登录内容