For this forum, I think you are probably better off doing as RealBlackStuff suggested and going through a slightly more official channel: phpbb3 RSS feed http://www.phpbb.com/community/viewtopi ... &t=1214645. That will probably be better tailored for the type of content these forums contribute.
For my site however, I don't use PHPBB or any other pre-made CMS, so here is what I found out for making basic RSS feeds from scratch. (It's a lot easier than I thought)
Essentially all you need is a single XML in your home directory that you link to from other pages. For example rss.xml , and you can make simple HTML text hyperlinks, or image links to it.
Here is the basic template for any RSS feed (They are basic enough you can update them by hand if you really wanted to)
Code: Select all
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title> The title of your RSS Feed Goes Here </title>
<link> http://www.yoursite.com/linktoRSSFile.xml </link>
<description> Brief description of the content provided in your RSS feed. </description>
<item>
<title> RSS item title </title>
<link> http://www.yoursite.com/link_to_item_page </link>
<description> Description of item you just linked to </description>
</item>
<item>
<title> RSS item title </title>
<link> http://www.yoursite.com/link_to_item_page </link>
<description> Description of item you just linked to </description>
</item>
</channel>
</rss>For my site however since I do not want to update it manually every time I add something, I wrote a PHP script that retrieves the last 10 articles from my database. All I do is call this script whenever I add a new story to my site and it automatically rebuilds the XML file with the new information. I'll just post the code (with some edits to protect my server's privacy) and answer your questions as they come (if you have any). Just fair warning, I wrote the script to be rather verbose. You could condense a lot of it into single line statements, but I wrote everything out to make it a little easier to understand.
Code: Select all
<?php
//Connect to DataBase
$conn = mysql_connect("server_host", "mysql_db_user", "mysql_db_password") or die(mysql_error());
mysql_select_db("my_database",$conn) or die(mysql_error());
//Fuction to catch any forbidden XML characters and replace them with appropriate entities
function safeText($text_in) {
$patterns[0] = '/&/';
$patterns[1] = '/>/';
$patterns[2] = '/"/';
$patterns[3] = '/\'/';
$patterns[4] = '/</';
$replacements[0] = '&';
$replacements[1] = '>';
$replacements[2] = '"';
$replacements[3] = ''';
$replacements[4] = '<';
$safe_text = preg_replace($patterns, $replacements, $text_in);
return $safe_text;
} // End Function
//Open XML File to Rebuild
$file_in = "c:\\wwwroot\\rss.xml"; //Change this to whatever path your rss.xml file is in
$open = fopen($file_in,"w+");
//Build the header of the XML RSS Feed File
$rx = "
<?xml version=\"1.0\"?>
<rss version=\"2.0\">
<channel>
<title> My Awesome Site: News Feed </title>
<link> http://www.yoursite.com/rss.xml </link>
<description> Brief description of the content provided in your RSS feed. </description>";
//Get the Last 10 content entries from the database for inclusion in the RSS Feed
$query = "SELECT id, title, description FROM content_table ORDER BY date DESC LIMIT 10";
$query_res = mysql_query($query, $conn) or die(mysql_error());
while($query_info = mysql_fetch_array($query_res))
{
$id = $query_info['id'];
$title = stripslashes($query_info['title']);
$title = safeText($title); //Calls the safeText function above to correct any special characters that will cause errors in the XML file
$synopsis = stripslashes($query_info['synopsis']);
$synopsis = substr($synopsis, 0, 255) . "...";
$synopsis = safeText($synopsis);
$link = "http://www.yoursite.com/readcontent.php?id=$id"; //Whatever page holds the content you are linking to
$rx .= "
<item>
<title>$title</title>
<link>$link</link>
<description>$synopsis</description>
</item>";
}
//Close out the XML RSS Feed File With Appropriate Tags
$rx .= "
</channel>
</rss>";
fwrite($open,$rx);
fclose($open);
echo "RSS Feed Updated.";
?>


