Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP generate an RSS feed?

Options
  • 20-02-2008 9:58pm
    #1
    Closed Accounts Posts: 94 ✭✭


    Hi,

    I am tired and sick of looking for a way to do this.

    I've searched and searched and cannot find out how to do this.

    heres what i've got so far:

    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());

    $res = mysql_query("SELECT * FROM *** ORDER BY ** DESC");
    while ($row = mysql_fetch_array($res)){
    $str1=$row;
    $str2=$row;
    }


    I want to turn this info into an rss feed, with str1 as the title str2 as the description and str2 as the URL

    how can I do this??

    Thanks!


Comments

  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    I haven't tried doing this myself, but as I understand it, an RSS feed is an XML document, so you should be able to construct it in PHP and write it out to a file, then link to it.
    There's an interesting-looking sample at the bottom of this page you could try playing with.

    I'm curious about this myself actually, think I'll have a go at doing this later.


  • Registered Users Posts: 3,401 ✭✭✭randombar




  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    The most simple I could boil the XML down to was:
    <?xml version="1.0"?>
    <rss version="2.0">
    <channel>
    <title>My cool website</title>
    <link>http://www.example.com</link>
    <description>Cool stuff lols sheep</description>
    
    <item>
    <title>My latest article</title>
    <link>http://www.example.com/myarticle</link>
    </item>
    
    <item>
    <title>My other article</title>
    <link>http://www.example.com/myotherarticle</link>
    </item>
    
    </channel>
    </rss>
    
    It'll open as a feed if I serve it to the browser from apache, but using firefox to open the file locally just displays the xml tree (which it appears to do for all saved feed files I've tried)

    Would people reccomend supporting more than just RSS2 though? Or is there a really compelling reason not to do-it-yourself in the first place?


  • Closed Accounts Posts: 1,200 ✭✭✭louie




  • Closed Accounts Posts: 67 ✭✭BRENSH


    I think there might be something from the send framework that can help you

    i.e zend feed

    you can check it out here at http://framework.zend.com/manual/en/zend.feed.importing.html#zend.feed.importing.custom.importarray

    It could be what you are asking for.


  • Advertisement
Advertisement