Google Community
Latest Forums Rules Resources
Custom Search

Go Back   Google Community > Webmaster Forums > Web Design, Coding & Programming Forum

GoogleCommunity Sponsor
Cirtex Hosting
Use coupon "forum" for 50% Off!

Reply
 
LinkBack Thread Tools Display Modes
Old 03-05-2008, 01:59 AM   #1 (permalink)
Senior Googler
 
Join Date: Jul 2007
Posts: 129
Thanks: 0
Thanked 3 Times in 3 Posts
apg1985 is on a distinguished road
Having problems creating a RSS Feed

Hi,

Ive got a webpage with 5 different news pieces on it each one has a title and a small description. I want to create a rss feed out of them so people can add it to there site or use it for whatever they want really.

I dont understand how you get the xml file to call the information from the news page??

<item>
<title>News Feed</title>
<description>My news feed</description>
<link>www.mysite.co.uk</link>
</item>
apg1985 is offline   Reply With Quote
 
Sponsored Links
Old 03-05-2008, 12:02 PM   #2 (permalink)
Google Guru
 
andrew247's Avatar
 
Join Date: Oct 2005
Location: c:\GoogleCommunity
Posts: 3,368
Thanks: 3
Thanked 12 Times in 12 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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating account suresh Gmail Forum 1 07-12-2006 09:45 PM
Creating robots cruocitae Chit Chat 6 05-15-2006 10:17 PM
If You have a good RSS feed (your blog or any other rss feed marstrax Chit Chat 0 10-15-2005 12:02 PM
creating account suresh All About Google 1 01-01-1970 08:06 PM


All times are GMT -8. The time now is 11:49 PM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004–2007 Google Community