Making an RSS feed using PHP is not really that hard, but you need to understand how RSS feed files are compiled. If you look at an RSS feed file, it has the extension XML, and the information in the file is simply XML data that you put there. I created the feed
here for a friend's site using PHP. When they write a new article for the site, or edit an existing one, the RSS file also gets updated. Then anyone with it in their RSS reader will get the new file when they check.
Here's the file I wrote to update the RSS file. It's not particularly well coded or commented, but you should be able to understand it. If not, feel free to email or PM me.
CODE
<?php
//Include the database connection file
include('dbconn.php.inc');
$query = "SELECT * FROM fc_content ORDER BY timestamp DESC LIMIT 5";
$result = mysql_query($query);
$file = fopen("rss.xml", "w");
fwrite($file, '<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Ferret Crossing RSS Feed</title>
<link>http://www.ferret-crossing.co.uk/</link>
<description>All the latest information from Ferret Crossing delivered direct to your RSS reader.</description>
<language>en-gb</language>');
while($row = mysql_fetch_assoc($result)){
if($row['short'] == ""){
$description = $row['content'];
}
if($row['short'] != ""){
$description = $row['short'];
}
$description = strip_tags($description);
$description = substr($description, 0, 100);
fwrite($file, '<item>\n<title>'.$row["title"].'</title>\n<link>http://www.ferret-crossing.co.uk/</link>\n<description>'.$description.'...</description>\n</item>');
}
fwrite($file, '</channel></rss>');
fclose($file);
?>
Reply