+ Reply to Thread
Results 1 to 4 of 4

 

Thread: rss feed generation in php

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Aug 2005
    Location
    Bristol - UK
    Posts
    633
    Thanks
    31
    Thanked 5 Times in 4 Posts


    Hiya,

    Can anyone give me any tips on creating an rss feed using php from a database. As an example i'm trying to create an rss feed of the latest discounts added to less than full price and for it to update automatically every day.

    Thanks

    Jesse

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Mar 2004
    Location
    Stafford, UK
    Posts
    322
    Thanks
    1
    Thanked 4 Times in 2 Posts
    Hi Jesse,

    It's actually quite straight forward. Assuming that you're OK with the database code (it's no different in a page that generates a feed to any other page) - the following should help get you started...

    PHP Code:
    <?php
      
    // set the content type header to XML
      
    header("Content-Type: text/xml");
      
    // print the XML declaration
      
    print "<?xml version='1.0' encoding='UTF-8'?>";
      
    // print RSS header and channel info
      
    print "<rss>";
      print 
    "<channel>";
      print 
    "<title>Your Feed Title</title>";
      
      
    // now query your database to extract the items you want in
      // the feed into an array called, for example, $items

      
    foreach($items as $item)
      {
        print 
    "<item>";
        print 
    "<title>".htmlentities($item["title"])."</title>";
        print 
    "<link>".htmlentities($item["link"])."</link>";
        print 
    "<description>".htmlentities($item["description"])."</description>";
        print 
    "</item>";
      }
      print 
    "</channel>";
      print 
    "</rss>";
    ?>
    This would create a feed with the minimum required fields, but you could add all sorts of other information. The Wikipedia page is a good reference for the format:

    http://en.wikipedia.org/wiki/RSS_(file_format)

    Hope this helps!
    Developer of the Price Tapestry Price Comparison Script now with full WordPress Plugin!

  3. #3
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,008
    Thanks
    54
    Thanked 180 Times in 161 Posts

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Aug 2005
    Location
    Bristol - UK
    Posts
    633
    Thanks
    31
    Thanked 5 Times in 4 Posts
    Thank you - looks like I can manage it

+ Reply to Thread


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. The Good Feed Guide (For Merchants)
    By clint45 in forum Programming
    Replies: 18
    Last Post: 07-01-09, 11:54 PM
  2. Replies: 4
    Last Post: 17-03-07, 04:50 PM
  3. New RSS Feed at Phones2UDirect (and an update!)
    By phones2udirect in forum Affiliate Window & buy.at
    Replies: 2
    Last Post: 16-06-06, 10:54 AM
  4. New RSS Feed at Phones2UDirect (and an update!)
    By phones2udirect in forum Affiliate Future
    Replies: 0
    Last Post: 15-06-06, 01:45 PM
  5. Use vb.net or php to build product feed site?
    By accelerator in forum Programming
    Replies: 2
    Last Post: 18-01-05, 03:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2