Informatics Forum

Create RSS Feed on your Website

Posted on: January 5, 2008

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&gt;
<description>Deskripsi RSS</description>
<language>en-us</language>
<pubDate>$now</pubDate>
<lastBuildDate>$now</lastBuildDate>
<docs>http://domain.com</docs&gt;
<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;
?>

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Blog Stats

  • 131,473 hits

Category

Online

visitor stats
January 2008
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031  
%d bloggers like this: