Today I am going to tell u how to create a simple RSS feed with Php and MySql. This blog is for those who want to add their website or blog to Google feed burner.

About Google Feed burner :

Google Feed burner is one of the best place to promote your blog mainly. It will help you to reach your goal. It help your user to get your latest news feed you created. You don?t need to add single link one by one it will automatically access your newly created blog. You simply just create XML file that contains your all news feed links of your blog.

Simple Xml File Structure :

<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0">

<channel>

<title>Site Title</title>

<link> Your Blog address</link>

<description>Little Description about your blog</description>

<language>en-us</language>

<copyright>Copyright (C) </copyright>

<item>

<title>Your Blog Title </title>

<description><![CDATA[  Short Description of your blog  ]]></description>

<link>Complete link of your blog</link>

</item>

</channel>

</rss>

First create a table in your database

Xmlfeed.sql

--

-- Table structure for table `feed`

--

 

CREATE TABLE IF NOT EXISTS `feed` (

  `sr` int(11) NOT NULL AUTO_INCREMENT,

  `title` text NOT NULL,

  `desc` text NOT NULL,

  `link` text NOT NULL,

  PRIMARY KEY (`sr`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--

-- Dumping data for table `feed`

--

 

INSERT INTO `feed` (`sr`, `title`, `desc`, `link`) VALUES

(1, 'welcome to trinity blogs', 'Trinity blog is best programming blog for Beginners', 'your-blog-links.php'),

(2, 'About trinity blog', 'Trinity blogs are focused on window application, PHP, MySql ', 'your-page-link2.php');

Now we write code in Php and simply fetch the data from feed table and insert into XML layout. I hope you have basic knowledge of Php and Mysql.

Feed.php

 

<?php

/*

                * Simple and easy

*/

$conn = mysql_connect("localhost", "root", "");

$select_db = mysql_select_db("xmlfeed");

header("Content-Type: application/xml; charset=UTF-8"); // To output file in xml Format

$rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';

$rssfeed .= '<rss version="2.0">';

$rssfeed .= '<channel>';

$rssfeed .= '<title>Trinity Blog</title>';

$rssfeed .= '<link>http://www.trinityblog.in</link>';

$rssfeed .= '<description>RSS feed of trinityblog.in</description>';

$rssfeed .= '<language>en-us</language>';

$rssfeed .= '<copyright>Copyright (C) trinityblog.in</copyright>';

$query = "SELECT * FROM `feed` ORDER BY sr DESC";

$result = mysql_query($query) or die ("Could not execute query");

while($row = mysql_fetch_array($result)) {

                extract($row);

                /* Get category name */

                $rssfeed .= '<item>';

                $rssfeed .= '<title>' . $title . '</title>';

                $rssfeed .= '<description><![CDATA['. $desc. ']]></description>';

                $rssfeed .= '<link>' . $link. '</link>';

                $rssfeed .= '</item>';

}

$rssfeed .= '</channel>';

$rssfeed .= '</rss>';               

echo $rssfeed;

?>

And Final Output

This XML file does not appear to have any style information associated with it. The document tree is shown below.

 

<rss version="2.0">
<channel>
<title>Trinity Blog</title>
<link>http://www.trinityblog.in</link>
<description>RSS feed of trinityblog.in</description>
<language>en-us</language>
<copyright>Copyright (C) trinityblog.in</copyright>
<item>
<title>About trinity blog</title>
<description>
<![CDATA[
Trinity blogs are focused on window application, PHP, MySql
]]>
</description>
<link>your-page-link2.php</link>
</item>
<item>
<title>welcome to trinity blogs</title>
<description>
<![CDATA[
Trinity blog is best programming blog for Beginners
]]>
</description>
<link>your-blog-links.php</link>
</item>
</channel>
</rss>

 

 

Posted in: php