| | |
create html file from rss feed
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2007
Posts: 58
Reputation:
Solved Threads: 2
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!
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]
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Jan 2007
Posts: 58
Reputation:
Solved Threads: 2
•
•
•
•
Yes, you can save the HTML created from RSS feeds to files on the web server or to the database.
Can you plz provide me the reference material or tutorial link or anything that you think is appropriate.
thanks in advance.
•
•
•
•
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.
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Jan 2007
Posts: 58
Reputation:
Solved Threads: 2
•
•
•
•
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.
Thanks in advance!
•
•
•
•
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!
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Capturing data from txt file using JavaScript/HTML (JavaScript / DHTML / AJAX)
- mailing html file (PHP)
- Having a hard time with an RSS feed (RSS, Web Services and SOAP)
Other Threads in the PHP Forum
- Previous Thread: PHP unlink ERROR !!!
- Next Thread: Onclick and Onsubmit together
| Thread Tools | Search this Thread |
# address apache api array autoincrement beginner binary broken cakephp checkbox class clean cms code countingeverycharactersfromastring crack cron curl database date decode dehasher directory display dissertation dynamic echo email error fairness file files folder form forms function functions google href htaccess html image include incode insert ip javascript joomla legislation limit link login mail masterthesis match menu method mlm multiple mysql newsletters oop pagerank paypal pdf persist php play protocol query question radio random remote root script search server sessions simple sms soap source space spam sql support! syntax system table tutorial update upload url validator variable video web youtube






