Page 1 of 1

copying RSS feed / XML to local server (cloning to local)

Posted: Sun Nov 05, 2006 9:34 am
by RICKYJ
Hi there,

Im very new to php, but have figured out it may be the solution to my problem

I have created a java application that grabs RSS feed from a file, (say yahoo news)
then displays it as a ticker (this works client side). The problem is that java applets arent allowed to read from non local files without the use of a certificate.

I think there might be a way of copying the xml / rss feed to my servers local folder using php e.g:

from : http://rss.news.yahoo.com/rss/topstories
to : http://www.example.com/afile.html

I have had a search on google but couldnt see any easy way of doing this, it was all mostly database related and I just want to save it as a local file.

Does anyone know a simple bit of php that will do this, or a bit of info that I should be looking at?

Thanks for any help

Posted: Sun Nov 05, 2006 10:01 am
by feyd

Posted: Sun Nov 05, 2006 11:16 am
by RICKYJ
thanks, I had to use a small modification sice Im using php5:

Code: Select all

<?php
function file_put_contents_php4 ($location, $whattowrite) {
    if (file_exists($location)) {
        unlink($location);
    }
    $fileHandler = fopen ($location, "w");
    fwrite ($fileHandler, $whattowrite);
    fclose ($fileHandler);
}
 echo file_put_contents_php4("test.txt","Hello World. Testing!");?>


Thats the writting part working, now to get the other part to work, Im very thankful for your help

Posted: Sun Nov 05, 2006 11:19 am
by feyd
Did you try file_get_contents()?

Posted: Mon Nov 06, 2006 6:47 am
by RICKYJ
yes it all works now, thank you.
My only problem is that its a bit slow, but Im playing around with it so it doesnt need to download the data every time the page is viewed.

thanks for your help, I was completely new to php until last week and would have been stuck without your help

Ill offer the software out free once its complete