The source of each news item of a RSS feed

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
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

The source of each news item of a RSS feed

Post by lauthiamkok »

Hi,
When I feed a RSS to my website, is that possible to display/ print/ show where the source of each news item is coming from whether it is from BBC or other news channels?

This is the RSS feed which pulls the news from different RSS feed, using yahoo pipe, http://pipes.yahoo.com/pipes/pipe.run?_ ... render=rss

For instance,

National Media Briefing (title)
Citizens Advice, Save the Children, Hafal and Plantlife International are in the news today (description)
15 May, 10:29 (pubDate)
BBC (source?)


Election 2009: Numbers game sans big issues (Calcutta News) (title)
Varun Gandhi's hate speech, BJP's attack on Manmohan Singh as 'a weak prime minister' and the hitba... (description)
15 May, 10:17 (pubDate)
CNN (source?)

Thanks,
Lau
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: The source of each news item of a RSS feed

Post by divito »

I don't know how specifically you have yours setup, but as a way of identifying sources for all the feeds I use with Magpie, I made the following.

I edited it to showcase how you can do it.

Code: Select all

$feeds = array ('link1', 'link2', 'link3', 'link4');
 
foreach ($feeds as $feed ) {
    $rss = fetch_rss($feed);
 
foreach ($rss->items as $item ) {
 
    $url = $item['link'];
    $title = $item['title'];
    $desc = $item['description'];
    $date = $item['date_timestamp'];
    $bbc  = strpos($url, 'bbc.com');
    $yahoo = strpos($url, 'yahoo.com');
    $cnn = strpos($url, 'cnn.com');
 
  if ($bbc == true) {
 
//your output code here with BBC as source
 
} if ($yahoo == true) {
 
//your output code here with Yahoo as source
 
} //etc...
 
}
}
Add as many sources as you need.
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

Re: The source of each news item of a RSS feed

Post by lauthiamkok »

divito wrote:I don't know how specifically you have yours setup, but as a way of identifying sources for all the feeds I use with Magpie, I made the following.

I edited it to showcase how you can do it.

Code: Select all

$feeds = array ('link1', 'link2', 'link3', 'link4');
 
foreach ($feeds as $feed ) {
    $rss = fetch_rss($feed);
 
foreach ($rss->items as $item ) {
 
    $url = $item['link'];
    $title = $item['title'];
    $desc = $item['description'];
    $date = $item['date_timestamp'];
    $bbc  = strpos($url, 'bbc.com');
    $yahoo = strpos($url, 'yahoo.com');
    $cnn = strpos($url, 'cnn.com');
 
  if ($bbc == true) {
 
//your output code here with BBC as source
 
} if ($yahoo == true) {
 
//your output code here with Yahoo as source
 
} //etc...
 
}
}
Add as many sources as you need.
this is great. thank you very much.
cheers,
Lau
Post Reply