Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple rss feed

Tags:

php

xml

rss

i am trying to make a simple rss feed but the problem is when i run the file is says would you like to open rss.php ...

here is the code maybe im doing something wrong? i have put it in this format just to see it work.

<?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>
like image 465
same Avatar asked Sep 04 '10 10:09

same


2 Answers

You should output real <?xml version='1.0' encoding='ISO-8859-1'?>, not an entitized version. Since it's problematic due to php's own <?, echo it after the 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>
like image 65
aularon Avatar answered Oct 19 '22 01:10

aularon


Firefox doesn't get the content type in the header: application/rss+xml

Though it's the correct one, formally, text/xml seems to still be a standard with quite a few rss generators and browsers

Try changing the header to

header('Content-Type: text/xml; charset=utf-8');
like image 32
Guy Louzon Avatar answered Oct 19 '22 01:10

Guy Louzon