Generate RSS Feed With PHP


RSS feed lets your website visitors subscribe to get latest updates. If you are using WordPress or any other kind of CMS, you do not need this. Because all popular CMS comes with RSS feed. But this is not the case if you are developing your own custom coded website. For your website, you can easily create RSS feed. You only need to understand the structuer of RSS feed.

Sample RSS feed.

<?xml version='1.0' encoding='UTF-8'?> 
<rss version='2.0'> 

<title>Your Website Title</title> 
<link>Website URL</link> 
<description>Website description</description> 

<title>Article Title 1</title> 
<link>Article URL 1</link> 
<description>Article description 1</description> 

<title>Article Title 2</title> 
<link>Article URL 2</link> 
<description>Article description 2</description> 


You only need to follow this structure. You can add as many Items in RSS as you want. Fetch article title, link of the article, and short description. If you want to show full description, you can add full description.

include('db.php'); // add database connection in db.php file and include it.

$sql = "SELECT * FROM website_posts ORDER BY id DESC LIMIT 20"; 
$query = mysql_query($sql);

header("Content-type: text/xml");

echo "<?xml version='1.0' encoding='UTF-8'?> 
<rss version='2.0'>
<title>Webtips - Web Design Blog</title>
<description>WordPress, jQuery, CSS, HTML5 and web design blog</description>

while($row = mysql_fetch_array($query))

echo "<item> 
echo "</channel></rss>"; 


Tags: |

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Similar Articles


Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip | Part of Techlomedia Internet Pvt Ltd Developed By Deepanker