Convert text files into an RSS XML file.

txt2rss.php is a trivial PHP script that can take small multi-line text files, an RSS template file and produce an entire RSS 1.0 XML file. This requires some RSS and XML knowledge to configure your template file, but requires only a text editor for your updates. The act of updating is the motivation and primary activity of RSS.

The Web feed could be generated continously and on-demand from the input files, but it is advised that the output is generated and saved to a regular file. This can be managed well with a unix Make file (see a sample make file for txt2rss.php) to ease iterative updates.

Figure 1: Generating RSS from Text Files[D]

The figure above gives an overview of the generation of an RSS XML file by txt2rss.php using text files. The txt2rss.php script takes an rss.txt file with meta information about the RSS feed, including a URL and title. Multiple files named item1.txt, item2.txt, and item3.txt are also read by txt2rss.php. These are merged with an RSS template file named rss.xml to create a valid RSS 1.0 file, named here feed.xml.


The script needs a few bits and pieces from you:

Detailed example

Below is an example text file for the feed. It has the meta information of a feed and its associated Web site. It is suggested to have the file name rss.txt:

The Free Software Foundation
The Free Software Foundation (FSF), established in 1985, is dedicated to promoting free software.

This and other input files that determine the Web feed are in a simple text format where each field occupies one line of the text file. This can make for some long lines, but long-line support is available in most modern text editors. The first line is the URL, or "link", of your main Web site. The second line should be the title of the Web site. The third line is the description. The next two lines determine how often the feed changes, or when users should make sure they check to see if there are updates to the feed (and consequently your Web site). Possible values for the first of these lines (updatePeriod) include "weekly", "monthly", "daily". The values for the last line (updateFrequency) can be any positive integer for how many times in the specified period to check. In the example above, the RSS feed suggests updates happen once per week.

Here is an example text file for a feed item, named in our example event-20060103.txt:

First International Conference on GPLv3
Massachusetts Institute of Technology (MIT) on January 16 and 17, 2006
Eben Moglen

Like the RSS feed text file before, this file starts with a URL, a title and a description on the first three lines. The fourth line is the author of this item, but more likely is the author of the material at the URL link.[1]

Numerous files of format similar to event-20060103.txt would match the provided wildcard expression and be added as items to the RSS feed. The order of items is determined by the ordering of the file names as specified by the operating system.[2] One method of keeping chronological order of items is to keep everything in file names uniform except for a date of the form YYYYMMDD. Of course, this date format demands there be only one item per day (you probably wouldn't be using this system if that was a burden), but it will neatly keep your items in the order you expect.

Deleting items

Most items in a feed don't need to be deleted, most RSS aggregators that "consume" feeds hide old feed items from the user. However, "cleaning house" may be necessary on occasion to improve the performance of your feed over varying bandwidths.

Deleting an item is even easier than creating one. Simply, delete the file representing the item. If you are generating a static copy of your RSS feed, then be sure to regenerate it after you delete the file.

Renaming rather than deleting a file may be a better habit to keep an archive of previous items, and to also avoid mistaken removals of items.


Many RSS feeds found on the Web are only a small component of a larger Web application. Some of these larger Web applications include Web logs (or Blogs) and content management systems (CMS). Few packages exist that can generate small and simple RSS feeds. Such packages would help those with small and independently built Web sites with important feeds that change only infrequently.

This software gives small Web sites feeds and makes changing the feed or editing items simple. It does so by avoiding having to directly edit the delicate RSS and XML syntaxes. Making changes to the current items in the feed is as easy as editing (or creating) a new text file and deleting (or renaming) an outdated file.

This application's motivation was to support the activities of a small organization of computer enthusiasts. The organization had a discussion mailing list and a "vanilla" Web site maintained by a single individual. RSS feeds were considered a useful way to advertise the regular meetings that were posted to the Web site and announced to the mailing list. Unfortunately, meeting announcements did not streamline into RSS data, and the task of maintaining an RSS file by hand was overly difficult and not fun.

This program is released with the source code and as copylefted free software to give users the freedom to study and modify the program for their needs. For just using this software package you are not obligated to publish your changes. Consider sharing your improvements on to others, and when you do so, pass on the same rights and freedoms. This documentation is free, so feel free to use it in publishing your modifications and maintaining your version of the script.


This script requires some version of PHP, but I'm not sure which. It was developed under PHP 4.3.1, but should be pretty portable between versions with only minor modifications.

  1. Get the script
  2. Get the RSS 1.0 template file (It is well-formed!)
  3. Create multi-line files for both your feed and each of your RSS items as suggested in the detailed example above.

If the above directions are too difficult, then you can get a compressed file of the files listed above and this manual.

Related Links and References

End notes

  1. The author's name could be generated by the script by determining it from the user account that owns (creates the) file. This would take some changes to the PHP script among other trickery relevant to those blessed with authorization and authentication facilities for collaborating.
  2. The PHP programming language and libraries may be already ensuring the alphabetization of file names is consistent between ports)

CopyLeft 2006 Aaron Hawley $Author: ashawley $

Last modified: $Date: 2010/01/22 22:24:26 $

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Text being "A free book about free software", and Back-Cover Texts being "You have freedom to copy and modify this book".