Sharing With Passion

July 07, 2012

Posted by Sabar Santoso in , , | July 07, 2012 No comments
What Is RSS?
RSS is a format used by content providers to publish content. Originally, RSS stood for Rich Site Summary, but with the release of the RSS 2.0 spec in 2002, the name was changed to Really Simple Syndication.
RSS simplifies publishing by providing a standardized, no-frills approach to releasing content. No formatting is included with an RSS entry; only the content is sent. This allows for RSS aggregators,commonly referred to as feed readers, to accept and display RSS feeds from any number of sites in a uniform, easy-to-read manner.
The RSS format is built in XML, which learn more about in the next section. For a history of RSS, visit this article: http://en.wikipedia.org/wiki/RSS.


What Is XML?
XML stands for Extensible Markup Language. In the context of programming, extensible means that the developer can define the markup elements. This might sound odd, but it’s actually incredibly useful.
XML is, on a basic level, extremely simple. In a parallel with HTML, XML information is enclosed in tags; however, you can name the tags anything you want, and these tags are basically labels for the enclosed information.
For example, assume you want to send personal information about someone via XML. The markup might read as follows:

Jason
24
male

The benefit of XML is that it’s easy to read. Take another look at the information in the preceding example—you don’t need to be an XML expert to understand what the markup means. In the next section, you’ll learn how RSS uses XML to syndicate content.

Creating an RSS Feed
RSS feeds follow a general format that allows for large-scale, easy compatibility with any feed reader in use right now. The basic format for an RSS consists of a channel that includes a title, description, link, and language setting. Within the channel, you declare each entry as an item. Each item contains a title, description, link, the date it was published, and a unique identifier.

To create your feed, you need to create a new folder and file in the simple_blog project. Next, add a new folder called feeds, and then create a new file called rss.php and in that folder (the full path: http://localhost/simple_blog/feeds/rss.php).

Before you can run your file, you need to modify .htaccess. This is as simple as adding an additional file extension to the first RewriteRule that prevents any rewrite from occurring if a file ending in .php is accessed. To accomplish this, add the following line in bold to your .htaccess file:

RewriteEngine on
RewriteBase /simple_blog/

RewriteRule \.(gif|jpg|png|css|ico|swf|js|inc\.php|php)$ - [L]
RewriteRule ^admin/?$ admin.php [NC,L]
RewriteRule ^admin/(\w+)/?$ admin.php?page=$1 [NC,L]
RewriteRule ^admin/(\w+)/([\w-]+) admin.php?page=$1&url=$2 [NC,L]
RewriteRule ^(\w+)/?$ index.php?page=$1
RewriteRule ^(\w+)/([\w-]+) index.php?page=$1&url=$2


Describing Your Feed
Now that your file is created and being handled properly, you can start to mark up your feed.
Begin by adding a Content-Type header to the document (using the aptly named header() function). This header tells the browser to serve the file as XML.

Next, you need to output an XML declaration. However, this causes issues because XML declarations conflict with PHP short tags. You can get around this by using the echo command to output the declaration in double quotes, which eliminates the conflict.

Now you need to state what you are doing, which you accomplish by adding an tag with a version attribute. This tells any feed reader what it’s receiving and ensures the information received is handled properly.

Next, you add the channel declaration and your feed’s basic information. As mentioned previously, the basic information consists of the title, description, link, and language of your feed. Add the following code to rss.php to create your feed:

// Add a content type header to ensure proper execution header('Content-Type: application/rss+xml');
// Output the XML declaration echo "\n";
?>
My Simple Blog
http://localhost/simple_blog/
This blog is awesome.
en-us

At this point, you can load your RSS feed in a browser to see what it looks like without any items; you can load the information at http://localhost/simple_blog/feeds/rss.php


Note : You don’t want to do anything further with the feed as it appears in your browser. The blog is not available publicly, so subscribing to the feed won’t work in a feed reader at this time.

0 comments:

Post a Comment

Silahkan Isi Komentar Anda :

Search

Bookmark Us

Delicious Digg Facebook Favorites More Stumbleupon Twitter