PHP to RSS

Discussion in 'PHP' started by fgs, Mar 12, 2007.

  1. #1
    Hello I am looking to create some RSS feeds for my sites.

    More particular I am interested in how to write to RSS file from a PHP Mysql Query

    I imagine it would be something like:
    
    $qr = mysql_query("SELECT * FROM table WHERE something = thisorthat LIMIT10);
      while( $row = mysql_fetch_object($qr) ){
    write.to some.rss (<title>$row->title</title>... etc for <desc> ...)
      }
    
    PHP:
    If you know of any good tool or tutorial or simply could give me some code I would highly appreciate it.


    Thanks in advance
     
    fgs, Mar 12, 2007 IP
  2. JoshuaGross

    JoshuaGross Peon

    Messages:
    411
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Look up PHP scripts that do this or look at existing RSS documents and mimick their format. There's nothing to it (I've done it a few times). Just dissect the RSS format and print it out with your code.
     
    JoshuaGross, Mar 12, 2007 IP
  3. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont know how to do that :)
     
    fgs, Mar 12, 2007 IP
  4. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It is simple to write a RSS file :)
    Do you know the default RSS format? If not, let me know, I'll base my next reply on that :)
     
    DeViAnThans3, Mar 13, 2007 IP
  5. kobra

    kobra Member

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    You see for more info just go to wikipedia and search for RSS there you have all the infor you'd need
     
    kobra, Mar 16, 2007 IP
  6. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I figured it out, was a lot simpler than I expected
     
    fgs, Mar 16, 2007 IP
  7. fanatikhamsi

    fanatikhamsi Active Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #7
    <?
    header('Content-Type: application/xhtml+xml; charset=utf-8');
    $query=mysql_query("SELECT * from table WHERE something = thisorthat LIMIT10");
    $body="<?xml version=\"1.0\" encoding=\"utf-8\"?>
    <rss version=\"2.0\">
    <channel>
    <title>SistemBilgisi</title>
    <link>http://www.sistembilgisi.com</link>
    <description>SistemBilgisi</description>
    <copyright>(c) 2005,SistemBilgisi</copyright>
    "; 
    
    while($r = mysql_fetch_array($query)) {
    $body .="
    <item>
    <title>".$r[name]."</title>
    <link>http://www.sistembilgisi.com/".$r['id'].".html</link> //you are design the line for your links
    <description>".$r[text]."</description> 
    <pubDate>$r[date]</pubDate>
    </item>";
    }
    
    $body .="
    </channel>
    </rss>"; 
    echo $body;
    /*
    $path="rss.xml"; 
    $filenum=fopen($path,"w");
    fwrite($filenum,$body);
    fclose($filenum); 
    */
    ?>
    PHP:
     
    fanatikhamsi, Mar 18, 2007 IP
  8. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thank you very much, I also often see images in the rss feeds, but when you add <image></image> tags to the channel it does not go through in the validator, should I just insert images into description?
     
    fgs, Mar 18, 2007 IP
  9. fanatikhamsi

    fanatikhamsi Active Member

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #9
    I dont see images in the rss feeds with <image></image> tags
     
    fanatikhamsi, Mar 18, 2007 IP
  10. TomK32

    TomK32 Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yepp and use the regular <img> tag instead. Have a look at the Wikipedia entry on RSS ( http://en.wikipedia.org/wiki/RSS#Example_-_RSS_2.0 ).
     
    TomK32, Mar 19, 2007 IP
  11. prudentialwebdev

    prudentialwebdev Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Lets just say I dont know the default, (because I have to merge several sql fields to make the different rss fields) how would you go about this?
     
    prudentialwebdev, Mar 19, 2007 IP