Parsing Google News RSS with PHP -
i want parse google news rss php. managed run code:
<? $news = simplexml_load_file('http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=n&output=rss'); foreach($news->channel->item $item) { echo "<strong>" . $item->title . "</strong><br />"; echo strip_tags($item->description) ."<br /><br />"; } ?>
however, i'm unable solve following problems. example:
- how can hyperlink of news title?
- as each of google news has many related news links in footer, (and code above includes them also). how can remove description?
- how can image of each news also? (google displays thumbnail image of each news)
thanks.
there go, need particular situation:
<?php $news = simplexml_load_file('http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&topic=n&output=rss'); $feeds = array(); $i = 0; foreach ($news->channel->item $item) { preg_match('@src="([^"]+)"@', $item->description, $match); $parts = explode('<font size="-1">', $item->description); $feeds[$i]['title'] = (string) $item->title; $feeds[$i]['link'] = (string) $item->link; $feeds[$i]['image'] = $match[1]; $feeds[$i]['site_title'] = strip_tags($parts[1]); $feeds[$i]['story'] = strip_tags($parts[2]); $i++; } echo '<pre>'; print_r($feeds); echo '</pre>'; ?>
and output should this:
[2] => array ( [title] => los alamos nuclear lab under siege wildfire - abc news [link] => http://news.google.com/news/url?sa=t&fd=r&usg=afqjcngxbe4yszarh0kswejq_zdm_h-n4a&url=http://abcnews.go.com/technology/wirestory?id%3d13951623 [image] => http://nt2.ggpht.com/news/tbn/ohh43xorrwiw1m/6.jpg [site_title] => abc news [story] => wildfire burning near desert birthplace of atomic bomb advanced on los alamos laboratory , thousands of outdoor drums of plutonium-contaminated waste tuesday authorities stepped ... )
Comments
Post a Comment