TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   RSS Parsing + multiple feeds?? (http://www.talkphp.com/general/4537-rss-parsing-multiple-feeds.html)

marxx 06-11-2009 10:19 PM

RSS Parsing + multiple feeds??
 
Hi all!

I have this problem about RSS parsing and multiple feeds..

I want to get feeds from several place and show them in one feed stream.. You can see example in here (google feed API whit javascript).

Script what I have being using is lastRSS and I have managed to get feeds showing but not in same stream.. Is there way to get it done via lastRSS script or should I try other one instead?

Could saving feeds info into database be one way??

Thanks for all help and hints!! :)


Ps. below is some example of this lastRSS script what I'm using, could there be something??

Code:

<?php

function ShowOneRSS($url) {
    global $rss;
    if ($rs = $rss->get($url)) {

            echo "<ul>\n";
            foreach ($rs['items'] as $item) {
                echo "\t<li><a href=\"$item[link]\">$item[title]</a> - <small><a href=\"$rs[link]\">$rs[title]</a></small></li>\n";
            }
            echo "</ul>\n";
    }
    else {
        echo "Sorry: It's not possible to reach RSS file $url\n<br />";
        // you will probably hide this message in a live version
    }
}

// include lastRSS
include "./lastRSS.php";

$rssall = array('http://applereviews.com/feed/',
                'http://www.datacenterknowledge.com/feed/',
                'http://feeds.feedburner.com/Woork');

// Create lastRSS object
$rss = new lastRSS;

// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir = './temp';
$rss->cache_time = 1200;
$rss->cp = 'UTF-8';
$rss->items_limit = 5;

foreach ($rssall as $url) {
    ShowOneRSS($url);
}
?>


jcorradino 06-12-2009 04:25 AM

this is untested, but it should work (or at least get you closer to where you need to be). I set it up to use an output buffer to decide whether or not to display the list tags, and then to display them around everything else, making it look like one workflow.

Please let me know if I am way off base here, I may have misunderstood what you are looking for.

PHP Code:

<?php

function ShowOneRSS($url) {
    global 
$rss;
    if (
$rs $rss->get($url)) {
            foreach (
$rs['items'] as $item) {
                echo 
"\t<li><a href=\"$item[link]\">$item[title]</a> - <small><a href=\"$rs[link]\">$rs[title]</a></small></li>\n";
            }
    }


// include lastRSS
include "./lastRSS.php";

$rssall = array('http://applereviews.com/feed/',
                
'http://www.datacenterknowledge.com/feed/',
                
'http://feeds.feedburner.com/Woork');

// Create lastRSS object
$rss = new lastRSS;

// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir './temp';
$rss->cache_time 1200;
$rss->cp 'UTF-8';
$rss->items_limit 5;

ob_start();
foreach (
$rssall as $url) {
    
ShowOneRSS($url);

$buffer ob_get_contents();
ob_end_clean();

if (
$buffer!="") {
    echo 
"<ul>\n";
    echo 
$buffer;
    echo 
"</ul>\n";
} else {
    echo 
"There was a problem fetching RSS feeds."
}
?>


marxx 06-12-2009 06:22 AM

Yey, Thank you jcorradino!! :)

This is what I was looking for and it worked like a charm! Well, third last line, the echo statement was missing ";" but who's counting?? ;)

Actually there is one more question.. lastRSS script can fetch pubDate from feed, is it possible to sort those feeds as date?

In ShowOneRSS function where is foreach, it fetch 'items' ($item[link], $item[title] ... ) and publish date would be $item[pubDate].. I have trying to find somekind of foreach sorting but I don't know is it possible.
But if you or someone else find a way, please let me know! :)


Thanks again!

jcorradino 06-12-2009 02:12 PM

you could most likely print_r($rs) to see what exactly is being set. So like this:

PHP Code:

<?php

function ShowOneRSS($url) {
    global 
$rss;
    if (
$rs $rss->get($url)) {
            
print_r($rs);
    }


// include lastRSS
include "./lastRSS.php";

$rssall = array('http://applereviews.com/feed/',
                
'http://www.datacenterknowledge.com/feed/',
                
'http://feeds.feedburner.com/Woork');

// Create lastRSS object
$rss = new lastRSS;

// Set cache dir and cache time limit (1200 seconds)
// (don't forget to chmod cahce dir to 777 to allow writing)
$rss->cache_dir './temp';
$rss->cache_time 1200;
$rss->cp 'UTF-8';
$rss->items_limit 5;

foreach (
$rssall as $url) {
    
ShowOneRSS($url);
}
?>

(note: this is a little hacked together, and like before, isnt tested, but it should get you close to what you need to do)


All times are GMT. The time now is 05:16 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0