Nge-Blog ala Kang Yunan

Icon

Kehidupan, IT, Teknologi Informasi, Gosip, Film, Artis, Budi Anduk, Sosial, Komunitas, Pemerintahan, Rumah Tangga, Masyarakat, Kuliner, Makanan, New Idea, Sport, Olahraga, Liputan, Ulasan, Renungan, Agama, Islam

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&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;
?>

Filed under: Internet, Programming, Web Application, , ,

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

%d bloggers like this: