How to: Create RSS Feed in PHP

akshitsethi —  August 21, 2013 — 1 Comment

RSS (Really Simple Syndication) is an easy way to make your content global and available to various platforms. Be it web or mobile, people can get your content via the RSS. So, it’s important to have RSS feeds for your website. In this tutorial, I will show you how easy it is to create feeds for your content in PHP.

First, let’s have a look at the RSS feed structure.

Keeping the above structure in mind we will fetch data from a dummy SQL table holding the content and render it in RSS format.

Please note that I always use PHP Data Objects for interacting with the database server. One of the reasons for this is the protection against SQL attacks (known as SQL Injection).

Have a look at the PHP code below which will output content in the RSS format for us.

Didn’t I told you in the beginning that it’s going to be easy?

akshitsethi

Posts

I am a designer+developer by profession and entrepreneur by passion. I work on LAMP platform and can design+develop small static websites to high performing enterprise web applications. In love with the web and addicted to Spanish.