create html file from rss feed

Thread Solved

Join Date: Jan 2007
Posts: 58
Reputation: crazynp is an unknown quantity at this point 
Solved Threads: 2
crazynp crazynp is offline Offline
Junior Poster in Training

create html file from rss feed

 
0
  #1
Mar 7th, 2007
Hi,Will anyone plz suggest me on how to build a html file from rss feed and store it in a webserver or is it possible to make and store html file from the contents of mysql database using php and then store the html file in the webserver. Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: create html file from rss feed

 
0
  #2
Mar 10th, 2007
Parsing an RSS file w/ PHP can be done in many different ways.

Usually they consist of these steps:

1) The RSS feed text is imported into PHP as a string.
2) The RSS feed text is then parsed by PHP into PHP Objects that represent the data in the RSS file (Feed Items, titles, description etc.)
3) The Objects are then used to create HTML output or some other format.

The easiest way to get started is to use an existing RSS Feed Parser for PHP.
A popular and simple one being Magpie RSS Parser.
http://magpierss.sourceforge.net/

A simple usage from the pages:

[php]
require_once 'rss_fetch.inc';

$url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>
";
foreach ($rss->items as $item ) {
$title = $item[title];
$url = $item[link];
echo "<a href=$url>$title</a></li><br>
";
}
[/php]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: create html file from rss feed

 
0
  #3
Mar 10th, 2007
Originally Posted by crazynp View Post
Hi,Will anyone plz suggest me on how to build a html file from rss feed and store it in a webserver or is it possible to make and store html file from the contents of mysql database using php and then store the html file in the webserver. Thanks in advance!
Yes, you can save the HTML created from RSS feeds to files on the web server or to the database.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 58
Reputation: crazynp is an unknown quantity at this point 
Solved Threads: 2
crazynp crazynp is offline Offline
Junior Poster in Training

Re: create html file from rss feed

 
0
  #4
Mar 10th, 2007
Originally Posted by digital-ether View Post
Yes, you can save the HTML created from RSS feeds to files on the web server or to the database.
Thanks very much. I have alraedy created the feed and reader. As i am dealing with many domains. So I was told to put less load in the site with rss feed. that's why I have to save the rss data after some interval of days.

Can you plz provide me the reference material or tutorial link or anything that you think is appropriate.

thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: create html file from rss feed

 
0
  #5
Mar 10th, 2007
Originally Posted by crazynp View Post
Thanks very much. I have alraedy created the feed and reader. As i am dealing with many domains. So I was told to put less load in the site with rss feed. that's why I have to save the rss data after some interval of days.

Can you plz provide me the reference material or tutorial link or anything that you think is appropriate.

thanks in advance.
Do you want to cache the RSS feed or the HTML file you create from the RSS Feed.
Usually, you would just cache the RSS feed (XML file) but caching the HTML file should be no different.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 58
Reputation: crazynp is an unknown quantity at this point 
Solved Threads: 2
crazynp crazynp is offline Offline
Junior Poster in Training

Re: create html file from rss feed

 
0
  #6
Mar 10th, 2007
Originally Posted by digital-ether View Post
Do you want to cache the RSS feed or the HTML file you create from the RSS Feed.
Usually, you would just cache the RSS feed (XML file) but caching the HTML file should be no different.
I want to make an html file from the rss feed and store it in .html/.htm format and make it static unless I want to change the contents by again running the specific code which gets data from the feed and again changes the contents of that page. But I am tusck in the midway on how to grab data from the feed and make static html page.

Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: create html file from rss feed

 
0
  #7
Mar 11th, 2007
Originally Posted by crazynp View Post
I want to make an html file from the rss feed and store it in .html/.htm format and make it static unless I want to change the contents by again running the specific code which gets data from the feed and again changes the contents of that page. But I am tusck in the midway on how to grab data from the feed and make static html page.

Thanks in advance!
Can you post the PHP Code you have for parsing the RSS File?

Lets say these are the steps right now.

1) Retrieve remote RSS file from URL
2) Parse RSS file into PHP Objects
3) Iterate through PHP Objects to generate HTML
4) Echo HTML

In order to cache the generated HTML, you would need something like:

1) Check if Local HTML file exists for the URL
2) If file exists, check last modified date of local HTML file
3) If the local file has not expired, echo local HTML file contents
4) If local file does not exist, or is expired,
Retrieve remote RSS file from URL
5) Parse RSS file into PHP Objects
6) Iterate through PHP Objects to generate HTML
7) Cache HTML to local file
8) Echo HTML

You can identify each remote RSS URL uniquely by creating a hash of the URL. Then name your local files after this hash.

A hash is a "unique" fixed length string, generated for any arbitrary set of characters.

eg: Create a hash that identified a URL

[PHP]$url = 'http://example.com/rss.xml';

$hash = md5($url);[/PHP]

Now if we can write the url contents to local file

[PHP]$contents = url_get_contents($url);

file_put_contents('cache_dir/'.$hash, $contents);[/PHP]

When the time comes to check if a local version of a url exists, you can do so:

[PHP]if (file_exists('cache_dir/'.md5($url)) { /* exists */ } else { /* not exists */ }[/PHP]

To check when a file was modified use:
[PHP]
filemtime($file);[/PHP]

In our example:

[PHP]$mtime = filemtime('cache_dir/'.md5($url));[/PHP]

So if you want files cached for 1 hour, you can do:

if (($mtime + 3600) > time()) {
/* file is fresh */
}

Note: time() is the seconds from Unix Epoch. 1hr is 3600 secs. $mtime is seconds from unix Epoch when file was last modified.

Now the above will just cache the generated HTML file for 1 hour blindly. It does not check if the actual RSS feed has been modified or not...

A better approach would be to generate database entries for each RSS FEED Item/article.
Or cache each RSS feed Item individually to its own file. Then you can keep track of changing RSS feeds better.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 58
Reputation: crazynp is an unknown quantity at this point 
Solved Threads: 2
crazynp crazynp is offline Offline
Junior Poster in Training

Re: create html file from rss feed

 
0
  #8
Mar 11th, 2007
Thanks digital-ether, it worked for me.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: create html file from rss feed

 
0
  #9
Mar 11th, 2007
You're welcome. Glad to have helped.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: alan_ot is an unknown quantity at this point 
Solved Threads: 0
alan_ot alan_ot is offline Offline
Newbie Poster

Re: create html file from rss feed

 
0
  #10
Mar 16th, 2009
Hello.
Very helpful thread.
Magpierss works perfectly.
But need to limit entries per page.
How to do this?
Thank for any help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC