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:

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>
";
}

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.

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.

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.

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!

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

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

$hash = md5($url);

Now if we can write the url contents to local file

$contents = url_get_contents($url);

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

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

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

To check when a file was modified use:

filemtime($file);

In our example:

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

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.

Thanks digital-ether, it worked for me.

You're welcome. Glad to have helped.

Hello.
Very helpful thread.
Magpierss works perfectly.
But need to limit entries per page.
How to do this?
Thank for any help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.