Home     Articles & Projects     Products & Web Services     Forum

RSS

Hi David
is it possible to create a rss feed from a page on my web site that is not in the data base of mysql. I have created a page of sales and coupons and would like create a feed for it.
Thank You in advance

Dean

Hi Dean, Creating an RSS

Hi Dean,

Creating an RSS feed can be as simple as just publishing a static document containing the appropriate XML, but the "clever" thing to do would be to keep your coupons and a text file, and then use that text file to generate both the HTML page and the RSS feed - then you only need to keep one place updated.

What sort of format are your coupons in? Do you basically just have a title and a link, for example "Save 20% at Merchant using code XYZ123" and then your standard affiliate link to that merchant?

Hi David Thanks for the

Hi David
Thanks for the reply and yes that is all it is. Here is the link to the page http://www.publicanimal.com/coupon/index.php then if I could create a rsss feed I could have it read on my other sites.
Thank You
Dean

Hi Dean, Have a look at the

Hi Dean,

Have a look at the following for starters. The couponsRSS.php script should work as-is, and then you can simply merge the couponsHTML.php code into your existing PHP page.

To start with, create a text file in the same directory as the scripts called coupons.txt, containing a comma separated list of coupons, in the format:

affiliate URL,Coupon Text

For example:

http://www.example.com/?p=123&a=456&offer=789,Save 10% on blue widgets at example.com
http://www.example.net/?affiliate=123,Save 50% on everything at example.net

With the text file in place, here are the two scripts:

couponsHTML.php

<?php
  $fp
= fopen("coupons.txt","r");
  while(!
feof($fp))
  {
   
$fields = fgetcsv($fp,1024);
    if (
$fields[0])
    {
      print
"<p><a href='".$fields[0]."'>".$fields[1]."</a></p>";
    }
  }
?>

couponsRSS.php

<?php
  header
("Content-Type: text/xml");
  print
"<rss version='2.0'>";
  print
"<channel>";
  print
"<title>Coupons</title>";
  print
"<link>http://www.example.com/</link>";
  print
"<description>Coupons</description>";
 
$fp = fopen("coupons.txt","r");
  while(!
feof($fp))
  {
   
$fields = fgetcsv($fp,1024);
    if (
$fields[0])
    {
      print
"<item>";
      print
"<title>".htmlentities($fields[1])."</title>";
      print
"<link>".htmlentities($fields[0])."</link>";
      print
"</item>";
    }
  }
  print
"</channel>";
  print
"</rss>";
?>

Hope this helps!
Cheers,
David.

Thank you David! It works

Thank you David!
It works great
Thanks Dean