Posted By

jmiller on 09/15/09


Tagged

php rss


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


RSS Generator


 / Published in: PHP
 

URL: http://css-tricks.com/snippets/php/rss-generator/

  1. <?php
  2.  
  3. // Connect to database... (you'll need to create this yourself)
  4. require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php';
  5.  
  6. // Run query...
  7. $getFeed = mysql_query("SELECT *
  8. FROM `rss_feed`
  9. ORDER BY `time` DESC
  10. ")or die(mysql_error());
  11.  
  12. // Output XML (RSS)
  13. echo '<?xml version="1.0" encoding="ISO-8859-1" ?>
  14. <rss version="2.0">
  15. <channel>
  16. <title>Your RSS Title</title>
  17. <link>http://the_location_of_your_feed/feed</link>
  18. <description>Description of your Feed</description>
  19. <language>English</language>
  20. <image>
  21. <title>website Logo</title>
  22. <url></url>
  23. <link>Link to image</link>
  24. <width>width</width>
  25. <height>height</height>
  26. </image>';
  27. while($rssFeed = mysql_fetch_array($getFeed)) {
  28. echo '<item>',
  29. '<title>', $rssFeed['item_title']</title>',
  30. '<link>', $rssFeed['link'], '</link>',
  31. '<description><![CDATA[ ,$rssFeed['description'],']]></description>
  32. </item>';
  33.  
  34. }
  35. echo '</channel>
  36. </rss>';
  37.  
  38. ?>

Report this snippet  

You need to login to post a comment.