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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RICKYJ
Forum Newbie
Posts: 15
Joined: Sun Nov 05, 2006 9:10 am

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

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

RICKYJ
Forum Newbie
Posts: 15
Joined: Sun Nov 05, 2006 9:10 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Did you try file_get_contents()?
RICKYJ
Forum Newbie
Posts: 15
Joined: Sun Nov 05, 2006 9:10 am

Post 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
Post Reply