How to Create RSS XML feeds with PHP

Situation

You have data in a text file or mysql database and want to produce one of those cool RSS feeds you see on the canned sites and the big news sites.

Solution

The biggest trick is transforming the http headers sent to the web browser. You do this using the php header() function, changing header to text/xml.

header ('Content-Type: text/xml; charset=ISO-8859-1');

You can take a look at this sample script to see this in action.

To get Firefox to recognize that your page has a link to a RSS feed on the page, just add this to the page’s head:

< link rel="alternate" type="application/rss+xml" title="RSS" xhref="http://www.mydomainurl/thephpscriptname.php" mce_href="http://www.mydomainurl/thephpscriptname.php" />

Hope this helps someone.

This entry was posted in WebTechnology. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>