|
Page 1 of 1 |
|
Posted: Tue, 17th Mar 2009 19:52 Post subject: Magpie RSS fetch PHP script not quite working, lil help? |
|
 |
I've been trying to get this script working, but there's one problem that I can't get past.
It's supposed to fetch the last 5 entries from the specified RSS feed and write the data to a text file (rss.txt). Unfortunately it seems as though each line overwrites the previous one, so only one entry is recorded instead of 5.
Here's the script.
Code: |
<?php require_once('rss_fetch.inc'); ?>
<?php
$rss = fetch_rss('http://feeddit.com/topics/apple.atom');
$items = array_slice($rss->items, 0, 5);
foreach ($items as $item) {
$href = $item['link'];
$out = fopen('rss.txt', 'w') or die('Cannot create output file');
fwrite($out, $href);
}
fclose($out);
;
?>
|
I think I need a "\n" in there somewhere, but I'm not sure and I've tried all that I can think of. Any ideas?
|
|
Back to top |
|
 |
lhzr
Posts: 3902
Location: RO
|
Posted: Tue, 17th Mar 2009 20:14 Post subject: |
|
 |
use fopen('rss.txt', 'w+') instead of fopen('rss.txt', 'w')
|
|
Back to top |
|
 |
lhzr
Posts: 3902
Location: RO
|
Posted: Tue, 17th Mar 2009 20:17 Post subject: |
|
 |
and open the file only once, if you do that you don't need to append instead of overwriting (w+ insteand just w):
Code: | <?php require_once('rss_fetch.inc'); ?>
<?php
$rss = fetch_rss('http://feeddit.com/topics/apple.atom');
$items = array_slice($rss->items, 0, 5);
$out = fopen('rss.txt', 'w') or die('Cannot create output file');
foreach ($items as $item) {
$href = $item['link'];
fwrite($out, $href);
}
fclose($out);
?>
|
the original script kept reopening the file for every item and the file was opened in overwrite mode, deleting it's contents every time.
|
|
Back to top |
|
 |
|
Posted: Tue, 17th Mar 2009 20:56 Post subject: |
|
 |
Tnx man. I see what I did wrong, now.
|
|
Back to top |
|
 |
lhzr
Posts: 3902
Location: RO
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|