tutorial

tutorial » PHP-tutorial » Implementing rss feed writer in php

Implementing rss feed writer in php


13 December 2011 , 6:42 pm

poster-Implementing rss feed writer in php

Hello Guys! Implementing rss Feed writer in Php is pretty easy.we will be collecting the data dynamically from our blog table for implementation of php feed writer.This feed writer is for rrs 2.

you can easily create feeds for your website or blog using this simple code.the code is written using structured programming.perhaps i will write the oops code for feed writer in my next post.

this code is very is and simple for the beginners.

lets see below the XML format for the for RSS FEED:

<RSS VERSION="2.0">
<CHANNEL>
<TITLE>YOUR WEBSITE TITLE</TITLE>
<LINK> WWW.YOURWEBSITENAME.COM </LINK>
<DESCRIPTION>	A LITTLE DISCRIPTION OF YOUR SITE	</DESCRIPTION>
<LANGUAGE>EN-US</LANGUAGE>
<COPYRIGHT>COPYRIGHT (C) 2009 YOUR SITE.COM</COPYRIGHT>
<ITEM>
 <TITLE>YOUR POST TITLE</TITLE>
 <DESCRIPTION>	POST DESCRIPTION</DESCRIPTION>
 <LINK>LINK TO THE POST EG:WWW.YOURWEBSITE.COM/POST/SAMPLEPOST.HTM</LINK>
 <PUBDATE>FRI, 30 SEP 2011 23:57:04 +0200</PUBDATE>
</ITEM>
</CHANNEL>
</RSS>

 

Now that You have seen the Basic format for the Xml Rss feeds.we will be using the this format in our php and web will generate this rss feed code using our php script.

Firstly you need to create a php script file and paste the script given below in it.you may give script any name but i recommend to create a folder named "FEED" then inside that folder create index.php and paste the code in file.

it will be like www.yourwebsitename.com/feed and you can see your feed xml.

The code is below. it is really- really simple.you just need to copy and paste and file require little bit of editing like : your databse name,table name for the blog.

 

THE Php Script:

<?php
    header("Content-Type: application/xml; charset=ISO-8859-1");
        $rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';
        $rssfeed .= '<rss version="2.0">';
        $rssfeed .= '<channel>';
        $rssfeed .= '<title>Skynet It Solutions Blog</title>';
        $rssfeed .= '<link>http://www.skynetitsolutions.com</link>';
        $rssfeed .= '<description>Get the latest Php,jquery,Ajax any many more Tutorials From Skynet it solutions Blog</description>';
        $rssfeed .= '<language>en-us</language>';
        $rssfeed .= '<copyright>Copyright (C) 2009 skynetitsolutions.com</copyright>';

         $con=mysql_connect('localhost',"your db user name"," your db password");
             mysql_select_db("your db name",$con);
        $query = "SELECT * FROM tableName where ORDER BY date DESC";//your query here
        $result=mysql_query($query);

        while(mysql_fetch_array($result)) {
        extract($row);
        $dis=str_split(stripslashes($row['description']),  strpos($row['description'], '.',250));
                    
        $rssfeed .= '<item>';
        $rssfeed .= '<title>' . $title . '</title>';
        $rssfeed .= '<description>' . htmlspecialchars(html_entity_decode(strip_tags($description[0]),ENT_QUOTES)) . '</description>';
        $rssfeed .= '<link> http://www.yourwebsite.com/blog/post/$title. '</link>';
        $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>';
        $rssfeed .= '</item>';
        }

        $rssfeed .= '</channel>';
        $rssfeed .= '</rss>';

        echo $rssfeed;
?>

Please Comment if you like this post.

 

 



Postedby:admin

Posted Under:tutorial    Category:PHP-tutorial

SHARE POST:


SHARE







FACEBOOK COMMENTS




COMMENTS

on 19 January 2012 at 4:13 pm sustanon says:

Its Pleasure to understand www.skynetitsolutions.com. The above articles is pretty extraordinary, and I really enjoyed reading your blog and points that you expressed. I really like to appear back over a typical basis,post a lot more within the topic. Thanks for sharing…keep writing!!!

on 25 January 2012 at 12:30 am web promotion says:

You could certainly see your enthusiasm in the work you write ON www.skynetitsolutions.com . The world hopes for even more passionate writers like you who aren't afraid to say how they believe. Always follow your heart.

on 25 January 2012 at 9:48 pm seo services says:

www.skynetitsolutions.com is the perfect blog for anyone who wants to know about this topic. You know so much its almost hard to argue with you (not that I really would want…HaHa). You definitely put a new spin on a subject thats been written about for years. Great stuff, just great!

on 26 January 2012 at 2:35 pm sustanon says:

Thank you for the sensible critique on www.skynetitsolutions.com . Me & my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such great information being shared freely out there.

on 5 February 2012 at 6:20 pm admin says:

Thx Guys for liking this post

Write Your Thoughts


Name:

Email:

Comment:




LOGIN


Email:
Password:

Not Registered yet? Sign Up here..


FIND US on FACEBOOK

Blog Archive

Latest News

World News Headlines - Yahoo! News

Get the latest world news headlines from Yahoo! News. Find breaking world news, including analysis and opinion on top world stories.
05/20/2012 01:55 AM
Blind Chinese activist Chen arrives in New York

Blind Chinese dissident Chen Guangcheng is helped from a vehicle as he arrives in New YorkNEW YORK (Reuters) - Blind Chinese dissident Chen Guangcheng arrived in the United States on Saturday and declared "equality and justice have no boundaries" after China let him leave a Beijing hospital to quell a sensitive diplomatic rift between the two countries. Chen escaped from house arrest in northeastern China last month and sought refuge in the U.S. Embassy in Beijing, embarrassing China and creating an uncomfortable backdrop for U.S. Secretary of State Hillary Clinton's visit to improve ties between the world's two biggest economies. ...



05/20/2012 12:28 AM
World leaders back Greece, vow to combat financial turmoil

G8 leaders speak at the start of the first working session of the G8 Summit at Camp DavidCAMP DAVID, Maryland (Reuters) - World leaders backed keeping Greece in the euro zone on Saturday and vowed to take all steps necessary to combat financial turmoil while revitalizing a global economy increasingly threatened by Europe's debt crisis. A summit of the G8 leading industrialized nations came down solidly in favor of a push to balance European austerity - an approach long driven by German Chancellor Angela Merkel - with a new dose of U.S.-style stimulus seen as vital to healing ailing euro-zone economies. But it was clear that divisions remained. ...



05/19/2012 06:58 PM
Syria bomb kills 9, Damascus blames foreign plot

Residents and security personnel gather at the site of an explosion in Deir Al-ZourBEIRUT (Reuters) - A car bomb killed nine people at a Syrian military post in the eastern city of Deir al-Zor on Saturday, an attack the government said was the latest proof that an uprising against President Bashar al-Assad was a foreign plot. The official SANA news agency said the blast had been the work of a suicide bomber, and had also wounded about 100 people, including guards, at what it called military installations. International pressure and an U.N.-backed peace plan has failed to quell Syria's turmoil. ...



05/20/2012 02:26 AM
5.9-magnitude earthquake strikes near Bologna, Italy
(Reuters) - A 5.9-magnitude earthquake struck near Bologna, Italy, on Sunday, according to the U.S. Geological Survey. The quake, which initially registered at magnitude 6.3, was centered 22 miles north-northwest of Bologna in northern Italy at a relatively shallow depth of 6.3 miles, the USGS said. The last major earthquake to hit Italy was a 6.3 magnitude quake in the central Italian city of L'Aquila in 2009, killing nearly 300 people. In January, a 5.3-magnitude quake in northern Italy was felt in Genoa, Bologna, Turin and Italy's financial capital, Milan. (Writing by Doina Chiacu)
05/19/2012 11:52 PM
G8, raising pressure on Iran, puts oil stocks on standby

French President Hollande, U.S. President Obama, Britain's Prime Minister Cameron, Russia's Prime Minister Medvedev and Germany's Chancellor Merkel at the start of the first working session of the G8 Summit at Camp DavidCAMP DAVID, Maryland (Reuters) - Leaders of the Group of Eight major economies raised the pressure on Iran on Saturday, signaling their readiness to tap into emergency oil stockpiles quickly this summer if tougher new sanctions on Tehran threaten to strain supplies. "We remain united in our grave concern over Iran's nuclear program," the G8 leaders said in a statement summing up the results of their meeting in Camp David in rural Maryland. ...



Latest News