PHP RSS feed generator form to entering data to a tableIf you are a web publisher or maintain web sites then it is a good idea to give RSS feed to your visitors or other webmasters to publish your contents in their websites or in other Medias. RSS is quite popular in the field of content syndicating and going to play a major role in days to come.
By using RSS feed in your web site you can tell about your site updates and new articles / pages to the world without much effort. Here we will discuss on creating a RSS feed by using PHP script. Here we will focus on developing XML format for RSS feed. There are many ways to do this and here we will discuss one of the way which this site uses.
There are two steps involved in developing a RSS feed. First we will update a table with new updates and second step is updating the RSS page from the table. You can bypass the table and directly update the RSS page but by using a table we can keep a history of previous updates and its date of publications.
The first step is creating a form and then storing the entered data to a table. Here the form is designed to take data as per the required format of RSS feed. We need four inputs, one is title (this will be used as anchored text so important for our keyword ranking), Link (the URL of the page), description and publication date. The publication date has to be in a particular format known as RFC-822 date format. The format looks like this
So we will pre populate the date field with present time in this format, but we will have option of changing it. Here is the sample form.
We will go with a simple date field for storing the RSS feeds, but we will have option of changing it.
You can download the zip file with all the scripts to create your own RSS feed or to understand how the script works at the end of this page. Inside this zip file these are the files available.
config.phpStore all database connection details and this page is included wherever database operation is involved.
rsspost.phpThis page display the form for the user to enter page details. This page post details to rsspostck.php where all the data is inserted to our rss table.
rsspostck.phpCollects all the form data from rsspost.php file and then stores them in a table.
update_rss.phpHere we will read the recent data from the table and update the xml file in the specified format. Now we will read the data from the table and with the new data we will update the xml file. We will be using PHP file open command to open the xml file and then enter the new data to this file and then close the file. You can read the related tutorials here to get the idea on how to handle files in PHP. We will use limit command in SQL to get the most recently added 6 records from the table. Here we have used the order by command with desc to collect the records from the end of the table. Here is our SQL to collect the records from the table. Here is the code of it.
After running of this update_rss.php file, one new rss.xml file will be generated. So you must give write permission to this directory to create this file.
This article is written by plus2net.com team.
PHP & XML getName(): Name of the XML element or tag children(): Children of a XML node count(): Counting number of Children of an XML element simplexml_load_file(): creating object by reading from XML file simplexml_load_string(): creating object by using XML formatted string asXML: Getting string output or writing to file addAttribute(): Adding attribute to element of XML object addChild(): Adding Child element to element of XML object getNamespaces(): Getting NameSpaces from XML object XML from Database(): Generating XML from table records