View Single Post
Old 03-05-2008, 12:02 PM   #2 (permalink)
andrew247
Google Guru
 
andrew247's Avatar
 
Join Date: Oct 2005
Location: c:\GoogleCommunity
Posts: 3,386
Thanks: 3
Thanked 13 Times in 13 Posts
andrew247 is a glorious beacon of lightandrew247 is a glorious beacon of lightandrew247 is a glorious beacon of lightandrew247 is a glorious beacon of lightandrew247 is a glorious beacon of light
You can accomplish this using PHP. Assuming you have a database with the news in it, you could do something like the following:
feed.php
PHP Code:
<?php
header
('Content-type: application/rss+xml');
// Code by andrew247
class essentials{
  
private $rootURL;
  
// returns the base URL of the website
  
function rootURL(){
    
$this->rootURL "http://www.yourdomain.com";
    return 
$this->rootURL;
  }
}
class 
feed{
  
private $rssCode;
  function 
__construct() {
       
$this->rssCode Null;
   }
  
public function startRSS(){
    
$this->rssCode "<rss version=\"2.0\">\n";
    
$this->rssCode .= "<channel>\n";
    
$this->rssCode .= "<title>News</title>\n";
    
$this->rssCode .= "<link>http://www.yourdomain.co.uk/</link>\n";
    
$this->rssCode .= "<description>News feed with news entries.</description>\n";
    
$this->rssCode .= "<lastBuildDate>Fri, 05 Mar 2008 20:41:00 GMT</lastBuildDate>\n";
    
$this->rssCode .= "<language>en-uk</language>\n";
    echo(
$this->rssCode);
  }
  
public function endRSS(){
    
$this->rssCode "</channel>\n";
    
$this->rssCode .= "</rss>\n";
    echo(
$this->rssCode);
  }
}
class 
database extends essentials{
  
private $newsID;
  
private $newsTitle;
  
private $newsBody;
  
private $newsDate;
  
public function dbConnect(){
    
$db_username "dbusername";
    
$db_password "password";
    
$database "database_db";
  
    
mysql_connect("db.yourdomain.com",$db_username,$db_password) or die( "Unable to connect to database. :-O");
    
mysql_select_db($database);
  }
  
public function getFeed($perfeed){
    
$query "SELECT * FROM news WHERE accepted='1' order by id desc LIMIT $perfeed";
    
$result mysql_query($query);
    while (
$row mysql_fetch_assoc($result)){
      
$this->newsID $row['id'];
      
$this->newsTitle $row['title'];
      
$this->newsBody $row['body'];
      
$this->newsDate $row['date'];
      
$symbols = array("£","$","%","&","^","<br />","<br>");
      foreach(
$symbols as $symbol){
        
$this->newsBody str_replace("$symbol""""$this->newsBody");
      }
      include(
"./feed.entry.php");
    }
  }
}

$feed = new feed;
$dbQuery = new database;
$feed->startRSS();
  
$dbQuery->dbConnect();
  
$dbQuery->getFeed(10);
$feed->endRSS();

?>
feed.entry.php
PHP Code:
<?php
echo("<item>\n");
echo(
"<title>" $this->newsTitle "</title>\n");
echo(
"<link>" essentials::rootURL() . "/" $this->newsID "/" $this->newsTitle "/</link>\n");
echo(
"<guid>" essentials::rootURL() . "/" $this->newsID "/" $this->newsTitle "/</guid>\n");
echo(
"<pubDate>" $this->newsDate "</pubDate>\n");
echo(
"<description>" $this->newsBody "</description>\n");
echo(
"</item>");
?>
Untested, but should hopefully work.

Last edited by andrew247; 03-08-2008 at 08:48 AM. Reason: Ooops can't have public classes.
andrew247 is offline   Reply With Quote