How to Create RSS Feed on your Website

Very simple to create RSS feed. You just add header of XML file on your page header, and select from table and loop your data into xml format.

<?php
require_once(”dbconnection.php”);
$query = “select address, cat, desc, title from `category` limit 15?;
$result = mysql_query($query, $link);

while ($line = mysql_fetch_assoc($result))
{
$return[] = $line;
}

$now = date(”D, d M Y H:i:s T”);

$output = “<?xml version=\”1.0\”?>
<rss version=\”2.0\”
xmlns:content=\”http://purl.org/rss/1.0/modules/content/\”
xmlns:wfw=\”http://wellformedweb.org/CommentAPI/\”
xmlnsdc=\”http://purl.org/dc/elements/1.1/\”
>
<channel>
<title>Judul RSS FEED</title>
<link>http://domain.com/feed.php</link>
<description>Deskripsi RSS</description>
<language>en-us</language>
<pubDate>$now</pubDate>
<lastBuildDate>$now</lastBuildDate>
<docs>http://domain.com</docs>
<managingEditor>mail@mail.co.id</managingEditor>
<webMaster>mail@mail.com</webMaster>
“;

foreach ($return as $line)
{
$output .= “<item><title>”.htmlentities($line[’title’]).”</title>
<link>”.htmlentities($line[’address’]).”</link>

<description>”.htmlentities(strip_tags($line[’desc’])).”</description>
</item>”;
}
$output .= “</channel></rss>”;
header(”Content-Type: application/rss+xml”);
echo $output;
?>