Having an RSS feed on your website is a great way of sharing your content with the rest of the Internet. It’s not a new technology and it’s probably something that you use on a daily basis. If you have a blog or use any form of CMS, that software will most likely handle the creation of your RSS feed for you.
Sometimes, however, it might be necessary for you to create a RSS feed yourself. Perhaps you have just won a new client who’s current site has an old bespoke CMS which they like and want to keep, but you want to be able to publish their updated content via RSS. Hopefully this tutorial will help you to achieve this.
What is RSS?
RSS, in its current form, stands for Really Simple Syndication and is a family of web formats to publish frequently updated content. The RSS Feed (as it is commonly known) can then be read by the users feed reading software or by another website which wishes to ‘syndicate’ the content of that feed.
The RSS format is based on XML that is built using standardised tags. Here is an example of a basic RSS document, we will be generating something similar using PHP later in this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?xml version="1.0" encoding="ISO-8859-1"?> <rss version="2.0"> <channel> <title>My RSS feed</title> <link>http://www.mywebsite.com/</link> <description>This is an example RSS feed</description> <language>en-us</language> <copyright>Copyright (C) 2009 mywebsite.com</copyright> <item> <title>My News Story 3</title> <description>This is example news item</description> <link>http://www.mywebsite.com/news3.html</link> <pubDate>Mon, 23 Feb 2009 09:27:16 +0000</pubDate> </item> <item> <title>My News Story 2</title> <description>This is example news item</description> <link>http://www.mywebsite.com/news2.html</link> <pubDate>Wed, 14 Jan 2009 12:00:00 +0000</pubDate> </item> <item> <title>My News Story 1</title> <description>This is example news item</description> <link>http://www.mywebsite.com/news1.html</link> <pubDate>Wed, 05 Jan 2009 15:57:20 +0000</pubDate> </item> </channel> </rss> |
Take a look at the RSS Wikipedia page for a full history of RSS and it’s various different versions.
Creating the feed
As we know, RSS is made up of standardised XML tags which you would normally find in a flat XML file. What we are going to do is create this standard XML data dynamically using PHP. This means that the URL for our feed will end with the .php extension, but we will tidy this up later in the tutorial.
So, lets start building the PHP script. The first thing we are going to do is tell PHP what type of data we would like to output (I am going to break each section of the script down, but I will include it in full at the end):
1 2 | <?php header("Content-Type: application/rss+xml; charset=ISO-8859-1"); |
The header()
function that we have called is telling PHP to output our data using the XML MIME type as well as to use the ISO-8859-1 character set. This makes sure that our content is delivered to the users in the correct format.
Now we are going to define our database connection details and create the header XML tags for our RSS feed. I’m going to statically assign the feed information tags just to keep it simple, however, you may wish to expand on this to dynamically set these. That way, you can re-use this code as a function or even go a step further and use it to build your own PHP class. The actual feed data will be kept in a variable called $rssfeed
.
1 2 3 4 5 6 7 8 9 10 11 12 13 | DEFINE ('DB_USER', 'my_username'); DEFINE ('DB_PASSWORD', 'my_password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'my_database'); $rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $rssfeed .= '<rss version="2.0">'; $rssfeed .= '<channel>'; $rssfeed .= '<title>My RSS feed</title>'; $rssfeed .= '<link>http://www.mywebsite.com</link>'; $rssfeed .= '<description>This is an example RSS feed</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= '<copyright>Copyright (C) 2009 mywebsite.com</copyright>'; |
Next, we need to extract our data by looping through our MySQL database to create the <item>
tags. I’m not going to explain this part in too much details as it’s not point of this tutorial and you may do this differently. We are going to assume that our MySQL table (“mytable”) has columns called title, description, link and date which hold the relevant data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | $connection = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect to database'); mysql_select_db(DB_NAME) or die ('Could not select database'); $query = "SELECT * FROM mytable ORDER BY date DESC"; $result = mysql_query($query) or die ("Could not execute query"); while($row = mysql_fetch_array($result)) { extract($row); $rssfeed .= '<item>'; $rssfeed .= '<title>' . $title . '</title>'; $rssfeed .= '<description>' . $description . '</description>'; $rssfeed .= '<link>' . $link . '</link>'; $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>'; $rssfeed .= '</item>'; } $rssfeed .= '</channel>'; $rssfeed .= '</rss>'; echo $rssfeed; ?> |
The first part of this section connects to the MySQL database using the constants which we defined at the start of the script. Then we perform a basic SQL query to pull out all our data from the database in date order. The final part of the query, DESC
, ensures that the newest content will appear first in the users RSS reader.
Next, we look at each row of data from the results of the query using a while
loop. In each loop cycle, the first action performed is the extract()
function to create a set of variables that take the name of the columns of the database, in my case $title
, $description
, $link
, and $date
. We then add the data contained in these variables to our main $rssfeed
variable. When it reaches the final row of data, the while
loop ends and we apply the closing XML tags.
The final step of the script is to actually output the data we have collected. This is simply done by echoing the $rssfeed
variable. Here is the code in full:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?php header("Content-Type: application/rss+xml; charset=ISO-8859-1"); DEFINE ('DB_USER', 'my_username'); DEFINE ('DB_PASSWORD', 'my_password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'my_database'); $rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>'; $rssfeed .= '<rss version="2.0">'; $rssfeed .= '<channel>'; $rssfeed .= '<title>My RSS feed</title>'; $rssfeed .= '<link>http://www.mywebsite.com</link>'; $rssfeed .= '<description>This is an example RSS feed</description>'; $rssfeed .= '<language>en-us</language>'; $rssfeed .= '<copyright>Copyright (C) 2009 mywebsite.com</copyright>'; $connection = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect to database'); mysql_select_db(DB_NAME) or die ('Could not select database'); $query = "SELECT * FROM mytable ORDER BY date DESC"; $result = mysql_query($query) or die ("Could not execute query"); while($row = mysql_fetch_array($result)) { extract($row); $rssfeed .= '<item>'; $rssfeed .= '<title>' . $title . '</title>'; $rssfeed .= '<description>' . $description . '</description>'; $rssfeed .= '<link>' . $link . '</link>'; $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($date)) . '</pubDate>'; $rssfeed .= '</item>'; } $rssfeed .= '</channel>'; $rssfeed .= '</rss>'; echo $rssfeed; ?> |
I mentioned earlier that I would tidy up the .php extension of the feed. I don’t know about you, but I find this a little bit ugly. When you see RSS feeds that have been generated by WordPress for example, you don’t see the actual file name, you just get the containing folder. To do this, create a folder in the root directory of the site and call it ‘feed’. Create a file in this new folder called ‘index.php’ and copy the code above into it. This leaves us with a nicer looking feed URL, in the case of this example, http://www.mydomain.com/feed/.
It really isn’t that necessary to tidy the feed URL, but I think it just looks a little neater.
Conclusion
Now that you have created your feed, you can link to it from your site or publish it using a service such as FeedBurner. But there is an extra step which will allow your visitor’s browsers to automatically detect the RSS feed on your site. In the <head>
section of you pages, include the following tag (obviously changing the URL to your feed):
1 | <link rel="alternate" href="/feed/" title="My RSS feed" type="application/rss+xml" /> |
Thanks for reading, it’s the first tutorial we have published and we hope it helps you out in some way. Please leave a comment below, we would love you hear what you have to say.
Resources
Comments
Comments are closed.
25th March 2009 at 8:50 am
Great article
With RSS becoming more and more popular over the years I have no doubt this will prove invaluable in the future.
Thanks
10th April 2009 at 6:57 am
FANTASTIC!
15th April 2009 at 1:48 pm
I think it’s easier to create an RSS feed using the DOM model than writing it out like this, as I do in my example.
It sounds intimidating, but I think you’ll find it is just as easy.
19th April 2009 at 8:28 pm
any reason you chose the ISO charset over utf8?
19th April 2009 at 10:34 pm
Hi Tim,
MySQL uses the Latin1 (ISO-8859-1) character set by default, so it seems to make sense to use this character set for my RSS feed as I am taking my information directly from a (default) MySQL database.
However, you raise a good point because I believe that all of the ISO-8859-1 characters are included within the UTF-8 set, so using either character set would have been valid.
Thanks for the comments Tim.
Ian
19th July 2011 at 5:29 pm
Hi Ian,
Great Stuff! its working fine in my project. but i could not understand why it shows only 6 feeds in my local host (wamp server).. i have added more than 20 feeds in my table.
kindly advice me how to display all feeds…
thanks a lot…
regards,
Jacob
18th May 2009 at 11:34 pm
Hi Ian,
You’re a legend! I was close to getting somebody in to code this for me but I decided to search online and stumbled across this article. It was spot on and the steps were detailed very well and were easy to follow.
Thanks
19th May 2009 at 5:45 am
Hi tkmk,
Thank you very much for the comments, I’m glad the article was helpful for you. Best of luck!
Ian
19th May 2009 at 5:38 pm
No problem. I have another question for you. Do you konw how I can remove the timestamp from the date? My DB doesn’t hold the time so the code shows a value of 00:00? Also I wanted to put “Posted on” in front of each date, but I’m struggling to find a solution to this too.
Thanks
19th May 2009 at 10:49 pm
Hi again tkmk,
Unfortunately, you cannot change the format of the date when you create the RSS feed. This is because the pubdate needs to be in the standard RSS format so that ALL feed readers understand it correctly.
The modifications you are trying to achieve will need to be applied at the feed reader end, i.e. when your feed is being read/displayed. If this is what you are trying to do, take a look at Simple Pie. It’s a great tool to allow you to simply display RSS feeds with PHP.
Hope this helps!
Ian
21st May 2009 at 1:30 pm
I’m building a feed currently with the data from mysql.
One issue is dealing with rogue characters, like a ’ curly apostrophe pasted from Word. I can’t control the database so I need to clean the data when I build the XML file. I could use CDATA but do you know of a function that will convert all these characters into accepted ones e.g. ’
Regards
21st May 2009 at 7:38 pm
Hi Mark,
Which character set are you using for your XML? If it is ISO-8859-1 like in my example, try changing it to UTF-8.
Also, for a function to clean up these curly quotes, take a look http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php. Make sure you read the comments too as there is some useful information there as well.
Hope this helps!
Ian
1st January 2010 at 11:07 am
you are so bad boy
22nd May 2009 at 7:57 am
Thanks Ian – that link got me sorted.
24th May 2009 at 5:13 pm
This is great, thanks a lot of the tutorial. I wasn’t able to make anything else work but this worked perfectly after a little fitting. Thanks. 🙂
1st July 2009 at 5:21 am
Thanks!
7th October 2009 at 9:11 am
I got an error at line
XML Parsing Error: not well-formed
Location: http://mysite.com/podcast/rss.xml
Line Number 10,
Column 19:$rssfeed .= ”;
———————–^
7th October 2009 at 1:32 pm
Hi Polat,
Try changing the file extension of your file to .php. If it has a .xml extension, the server will not parse the PHP code and you will end up with issues that you are seeing.
Let me know how you get on,
Thanks,
Ian
1st November 2009 at 6:24 am
Wow! Thanks a lot Ian. Works great!
14th December 2009 at 9:35 pm
Hi, thanks for this great tutorial. I can’t believe how much i searched for this stuff especially the part where u taught about browser auto – detecting feed support using <link rel … . Thanks alot buddy. Kudos 🙂
18th December 2009 at 8:54 am
Good Tutorial. Very easy to follow up.
Thanks
29th December 2009 at 2:07 pm
Thanks so much for this article.. I have seen a few tuts on the subject before but you do an outstanding job describing the process. BTW.. I signed up for the RSS for this site 😀
29th December 2009 at 2:43 pm
Hi Kevin, thanks for the kind words and for signing up to our RSS feed. I hope it helps you out!
Ian
27th January 2010 at 8:13 pm
Nice! Another great class from the prestigious WIU (WWW Internet University)
Thanks…
14th March 2010 at 8:50 am
Thanks for sharing this script, this is exactly what I have been looking for. You have made it easy to understand. This makes managing rss feeds so simple. thanks again
11th April 2010 at 7:30 pm
Brilliant tutorial, really easy and straigt forward to follow – I’ve just set up my first RSS!
12th April 2010 at 9:16 am
Hi Leigh,
Thanks for the comments, I’m glad it was useful for you.
Cheers,
Ian
14th April 2010 at 8:07 pm
Hi man, i am getting an error in that part;
$rssfeed = ”;
because “?>” this closes to php tags i guess, how can fix this ?
thanks
14th April 2010 at 10:57 pm
Hi,
I’m sorry to hear that you are having a problem. Make sure that the XML header line is completely wrapped in single quotes and that there is no space before the
?>
. Otherwise, this probably isn’t the cause of your problem.Let me know how you get on.
Thanks,
Ian
10th May 2010 at 5:58 am
hi , i copied the above code and pasted in php file . but when i execute the file in the browser it is redirecting to yahoo site..http://add.my.yahoo.com/rss?url=http%3A%2F%2Flocalhost%2Ffeed%2Findex.php
when i renamed the as then it is diplaying the output in XML form . i dont about xml can u please help me
10th May 2010 at 8:07 am
Hi Rajesh,
It sounds like that is working correctly. Have a look to see what you default RSS reader is, it would imagine that it is set to Yahoo. When you execute the file, it will return the data in the RSS format and when your browser see this, it will try and open it in it’s default way.
Thanks,
Ian
12th May 2010 at 5:21 am
Hi Ian,
Thanks for your reply. i didnt understand one thing that is RSS case sensitive. why because i declared as RSS version=”2.0″ and declared some items i placed my code in server and when i clicks on “RSS” image then it is redirecting to yahoo and displaying the items list. if i give as rss version=”2.0″ then it is displaying the result as xml format.
12th May 2010 at 11:03 pm
Great guide Ian, the best I found and I’ve trawled a lot of sites.
I’ve now created my first RSS but the pubDate is returning 01 January 1970, 01:00:00
Any ideas how to fix it?
(PS I’ll also be using your Replace broken images tip – thanks)
12th May 2010 at 11:48 pm
Don’t worry now sorted – Thanks
28th May 2010 at 5:10 am
may be because your actual date is not in correct format.
4th May 2012 at 12:32 pm
How did you fix the time problem?
28th May 2010 at 5:07 am
hello, very nice guidance, I have created my website’s feed using ur tutorial. It is working very fine.you can visit my website http://santech.cogia.net thanks a lot.
31st May 2010 at 6:25 pm
Thanks a lot for the tutorial, really appreciate it.
26th July 2010 at 12:36 pm
i got this error:
Warning: Cannot modify header information – headers already sent by (output started at /home/******/public_html/newest-rss.php:2) in /home/*/public_html/newest-rss.php on line 4
26th July 2010 at 1:34 pm
problem, fixed, thanks
29th October 2010 at 8:41 am
Hello Shah Khan.
I have the same the problem. How to fix it. Please help me.
9th August 2010 at 3:10 am
Hi Ian,
You made my day, and RSS simple. Your script is a great base to start with and it got me almost to the end. I started from scratch using your code as an example and it worked out great.
I do would like to suggest people to use a RSS/Feed Validator to make their life easier, also adding a webMaster to the channel or even some images to item descriptions using CDATA is easy too.
In any case, thanks for your perfect guide.
Greetz, Roy
9th August 2010 at 12:13 pm
Hi Roy,
Many thanks for the comments, I’m glad that this was helpful for you!
Cheers,
Ian
5th September 2010 at 11:14 am
Did nobody limit their results?
$query = “SELECT * FROM my_table ORDER BY date DESC LIMIT 0,10”;
This example limits to 10, or any amount wish to display at maximum, offset 0 is the start, 10 is the stop.
16th September 2010 at 6:39 pm
Why are people still using this oldschool way to create XML? Nowadays there are much better ways to create XML. PHP has excellent functionality for this like SimpleXML and DOMDocument.
25th September 2010 at 10:34 pm
hello
i followed your instruction and then i try to execute the code but i’m get this below error
what should i do ?
XML Parsing Error: not well-formed
Location: http://localhost/gowri/rss/index.php
Line Number 1, Column 3:<?
–^
13th October 2010 at 11:18 am
very good amd easy to follow. I was looking for at least an hour before i found yours. a tip for those none english characters. Use
13th October 2010 at 11:21 am
![CDATA[‘.$inlagg.’]]
21st January 2011 at 9:25 am
Your guide got me heading the right direction after I hit a bit of a wall trying this myself during the implementation of a larger system. Thanks!
26th January 2011 at 1:19 pm
Hi, this looks great but I’m struggling somehow – I’ve set it all up as an index.php in a feed folder, pulling data from the database and I get a lovely ‘subscribe to this feed’ box at the top of the page, but none of the items list below – although they appear to be there in the source code – any idea what I may be doing wrong?
26th January 2011 at 1:54 pm
Sorry, this seems to be working now, I’ve no idea why but I’m delighted! Thanks for posting such a useful tutorial.
26th January 2011 at 3:51 pm
Hi Jem,
I’m glad it’s working for you!
Many thanks,
Ian
5th February 2011 at 2:03 am
This is nice article , but you should code something like feed won’t be execute all mysql query everything you need to cache it or write an file.
At least this works I will let you if I changed your codes regards.
10th February 2011 at 9:28 pm
So I take it that your feed gets created when you make a normal article or post on your website?
29th March 2011 at 1:38 pm
Thank you so much for this great information.
21st April 2011 at 6:17 am
I have copied your code and changed the database connections and tables. When I try to open that page iam getting a download link of that php file. Please help me out from this
28th April 2011 at 6:31 pm
Even I face the same problem as Chaitanya. Please help us.
And the feed I created will open in safari and IE7 but not in Firefox why it is so?
1st May 2011 at 9:57 am
@Suresh @Chaitanya I’m sorry to hear you are both having problems. It sounds like you have not specified the MIME type correctly at the top of the PHP file. Make sure that you have correctly added the
header()
function, this tells the browser that the content of the file is going to be in the RSS format.It also may be a problem with the encoding if you are using a language other than English. Try changing the encoded from ISO-8859-1 to something like UTF-8. You will need to change this both in the
header()
function and in thedeclaration.
I hope this helps!
1st February 2012 at 11:37 am
I am aslo facing the browser issue. RSS is working in IE & Firefox but its not working in Chrome…In Chrome it displaying xml as it is….I have tried by changing characterset to UTF-8 but did’t worked…..Please help me out.
thanks in advance….!
17th May 2011 at 5:21 pm
Quick and painless guide 🙂
Thanks!
10th June 2011 at 6:18 am
Its a great toutorial specially for the begineers like me who are trying to discover new stuffs….
Thanx a lot for the post…..
May God Bless u guys…
Regards
Shaikh Asim Ahmed M. H.
17th June 2011 at 2:58 am
Great tutorial sir…
20th June 2011 at 11:28 am
Neat and simple!! Thanks a lot! 🙂
29th June 2011 at 8:27 pm
Hi i want to place the thumbnail in my site RSS Feed.can any body tell me how to place thumb in RSS.
Thanks.
23rd July 2011 at 8:22 pm
good work. thanks lot
26th July 2011 at 9:56 am
Hi Ian,
Your tutorial is great..I just some have question: I have my search engine on my site and i want the result would be generated based on my feed? is there anything to do
Tnx.
lecole
3rd August 2011 at 8:30 am
Awesome Article helped alot
8th August 2011 at 8:57 am
good explanation for RSS Nice one!!!!!!!
14th August 2011 at 2:04 am
Hi Ian this is a great post. I like how you demonstrate creating a feed from content in a database. Many classes and tutorials I have found provide functionality to build an RSS feed, but leave you in the dark when it comes to database integration.
This tutorial uses a free Php class to generate Atom feeds as well as RSS:
http://www.code-tips.com/2011/08/how-to-generate-feed-using-php-atom-10.html
It uses the Php FeedWriter class ( http://phpfeedwriter.webmasterhub.net/ ) which works as an abstraction layer between the various formats. I haven’t used it much yet, but it seems good and is easy to use.
Thanks
12th January 2013 at 6:56 pm
Nice article! Very helpful if you are building a custom blog if you dont want to use wordpress.
16th August 2011 at 9:17 am
Works fine for entryes who doesn’t have html code.. however it’s any posibilities to echo the description by ignoring the html code?
8th September 2011 at 5:04 pm
Hi there, great tut. Does anyone know how to add a hard return to the ends of the lines so that it formats properly. Thank you in advance.
14th September 2011 at 8:00 am
This is a great tutorial Ian. Thank you for sharing it with us. It was really helpful.
20th September 2011 at 12:06 pm
This is really a great tutorial Thank you for sharing such a nice tutorial.
25th September 2011 at 12:24 pm
One problem… my feed is working but shows up as a giant paragraph. How can I get it spaced out nicely?
12th December 2011 at 11:50 am
simply superb…
22nd January 2012 at 8:02 pm
Nice tutorial. I normally use something like WordPress or Drupal to hack together a site. But for the site I just built, I had to do if from scratch. This tutorial should help me get the rss feed up and running to help me get more traffic. Many thanks!
23rd January 2012 at 10:07 pm
I need to understand one thing. This example of creation of an RSS feed on my website will automatically write information to my site?… or it wil feed other websites when I place information on my site? I am confuse. Please, help.
1st February 2012 at 9:41 am
I have created feed folder and included index file with code mentioned in this post. What next should I do to generate feeds. Please help me as I am doing this for first time.
thank you,
7th February 2012 at 7:29 am
Thanks, this actually helped a lot. I had no concept of how to write a RSS file until this.
8th February 2012 at 10:28 am
I have created feeds by following your steps. Feeds are displaying properly in firefox but in chrome it only displaying xml script……what should I do to overcome of this….Please help me out ..
thanks in advance….
8th February 2012 at 6:24 pm
Thanks for your very detailed tutorial. Ill be using this on my website’s custom blog 🙂
8th February 2012 at 6:28 pm
I also like to add that it would also be better if you save the output of the php script to an xml file and just have a cron job to run the php file. That way it would lessen the load on your server if your website is so busy. 🙂
17th February 2012 at 5:50 am
Thanks so much for this article. I applied this code for my website
13th March 2012 at 3:28 am
Thanks. It helped me.
24th March 2012 at 1:38 pm
Hi! if i want to create an rss feed for trovit.it (http://about.trovit.com/your-ads-on-trovit/italia/feed-it-lavoro/) in which it is demanded the use of “CDATA”, how can i modify the feed above in order to make it like TROVIT FEED? HELP ME PLEASE!THANKS
29th March 2012 at 4:36 pm
Hey Ian thanks a ton. Wanted to embed an RSS for my website and this saved me a lot of work!
24th April 2012 at 7:33 am
There are several ways to read RSS feed in PHP, but this one is surely one of the easiest.
channel->item as $entry) {
echo “link’ title=’$entry->title’>” . $entry->title . “”;
}
?>
Source:
http://phphelp.co/2012/04/23/how-to-read-rss-feed-in-php/
OR
http://addr.pk/a0401
1st May 2012 at 7:16 pm
Great explanation and basic code – just what I needed to get me started on a custom RSS feed.
Thanks 🙂
2nd May 2012 at 4:28 pm
Ian, when you are setting your $rssfeed variables, you reference other variables such as $title, $description, $link, and $date. Does this imply that you have columns in your SQL database with the same names?
21st May 2012 at 7:17 pm
Hi Mike,
That’s correct, I used the php
extract
function which creates variables with names form the keys of the array passed to the function – in this case, the keys in the array are the MySQL column names.Thanks,
Ian
4th May 2012 at 12:56 pm
HiIan,
After installing the code when I launch the page index.php every time in the internet browser a download window prompts automatically and the page doesn’t show any contents populated from database.
I’ve created the database table and make connection to the database properly. The table columns are id, title, description, link and date.
Please help.
4th May 2012 at 2:11 pm
I’m trying to replace my static xml feed with dynamic feed using the script.
index.php is being prompted for download on launch in the browser. This is really strange that I can’t cope with this simple script. Should I rewrite the mod rule in order to make this script active?
Any idea?
3rd June 2012 at 4:38 am
Thank you Ian I am using your script on my website and it is working perfectly.I wish if you can add thumbnail capability so news headlines could be displaying along with it’s images.
Thank you again
19th July 2012 at 9:29 am
Tnx… i’ll use your code… nice one
24th July 2012 at 9:57 am
Great Tutorial… Thanks a lot…:)
12th August 2012 at 1:43 am
Wow, I just tried 3 tutorials before I found this one. None of them worked and yours was flawless. Thanks!
2nd September 2012 at 9:59 am
thanks that was very helpful for me, i will try it and tell you results
2nd September 2012 at 1:07 pm
it worked fine on chrome but it display limited to feed length on firefox and not working on IE
12th June 2013 at 11:46 am
Hi Shima. Did you get any solution for the problem, as I am facing the same problem.]
Could you please let me know if you have got a solution
3rd September 2012 at 2:20 pm
Nice tutorial
4th September 2012 at 10:47 am
Hi Ian,
Awesome tutorial… everything is working fine.
I have small doubt regarding New Articles automatically load into XML File. and also you mentioned as some code inserted in header section. Can you please explain me clearly about this header part in my website.
6th September 2012 at 11:18 pm
Outstanding tutorial.
21st September 2012 at 7:02 am
Works like a charm. Thanks for tut
4th October 2012 at 3:01 am
Great tutorial ; i made a working rss from my news with it ; the title, date, description.
The only thing I’m missing is the picture ; is there a chance to explain how to add a picture (from the same database newstable) into this rss? Thank you!
10th October 2012 at 8:11 pm
Nice article !
any one can help me to create rss feeds for my php directory website
1st January 2013 at 4:55 pm
Wow, I just tried 3 tutorials before I found this one. None of them worked and yours was flawless. Thanks!
23rd January 2013 at 4:43 pm
THANKS!
header(“Content-Type: application/rss+xml; charset=ISO-8859-1”); -> Was really helpful.
28th January 2013 at 1:30 am
Hey Ian! I know this is an old post of yours but I had a question.
Strangely I’m a php developer so am very accustomed to queries to MySQL and coding. But my loop isn’t working for my feed. I get the most recent post. When a new post hits that’s all that’s displayed.
When I run it through http://feedvalidator.org it displays all of them (LIMIT 10) as I wrote the script.
Thought it might be my Mac Mail program I’m using to read my feed. But I get all of them from Apple and my blog (done in WordPress).
Any ideas as to why my loop is not behaving the way it should? From your code it should continue while there are results to my limit of 10.
Since this is an old blog of yours an email would be no problem.
2nd February 2013 at 1:52 am
Great thanks for this article.
but i have a problem. to my site http://www.development.name
if i want create rss on my site, but on this rss content from my site and other site. and then ORDER BY date publish.
can help me.??
9th February 2013 at 1:19 pm
great work! thanks!
This code rules!
21st February 2013 at 10:32 am
Hello this works fine, but when I check the valitation on many sites, shows an error:
XML parsing error: : XML or text declaration not at start of entity.
for this line: $rssfeed = ”;
21st February 2013 at 10:34 am
**for this line: $rssfeed = ”;
13th March 2013 at 1:56 am
is it possible to create it without mysql and get link from site map Automaticaly?
29th March 2013 at 5:17 pm
Old articles but great 😀
5th April 2013 at 11:10 am
I found very good help from this site.
11th April 2013 at 4:39 pm
I have found a great solution about xml with php for feed. And this is you. Thank you.
26th May 2013 at 4:48 am
i try the code but still error occur, BUT i thanks cause you were share a great code, how to add image in RSS
12th June 2013 at 11:40 am
Thanks for the post. It is very good and self explanatory.
This will help a lot of people, who want to create thier own RSS Feeds.
Keep up the good work. Cheers !
1st July 2013 at 5:19 pm
Nice post. Thanks. Mapitogrowmedium
26th August 2013 at 12:08 pm
The best Feed consumer library in PHP is RSSClient[1]
[1] https://github.com/desarrolla2/RSSClient
21st September 2013 at 8:18 am
Good Post.
Here you can find updated one:
http://www.discussdesk.com/create-rss-feed-with-php-mysql.htm
20th May 2014 at 3:00 pm
hi!Many congratulation for this tuturial. I have a problem with the encoding of the data. In my DB I’m using UTF-8. But not here, you can solve the problem in this code? thank you
9th June 2014 at 2:33 pm
Awesome, this is another one with source code:
http://www.bewebdeveloper.com/tutorial-about-how-to-create-an-rss-feed-with-php-and-mysql
12th June 2014 at 4:14 pm
Thank you for this. it helped me. Though I’ve not tested yet.
13th June 2014 at 4:40 am
tested. many thanks!
28th November 2014 at 11:26 am
Hi.
I want to use values from two columns in title tag how can i achieve this?
13th May 2015 at 10:48 am
Thanks for the post. It is very good and self explanatory.
21st February 2016 at 1:22 am
Sir….great work! thanks!
This code rules!
4th March 2016 at 6:46 pm
I’m trying to render my database’s timestamp as pubDate for the RSS feed. It’s unix time. I’ve searched far and wide around the web but I’m not really finding the answer, and this is my first stab at this kind of thing so I’d appreciate some help. Thanks in advance!
27th March 2016 at 5:24 pm
Ian,
Seems simple enough. I’m going to give this a go myself for our website.
17th September 2016 at 5:41 pm
great article you cleared lot of doubts.