Tuesday, January 20, 2015

PHP get Google News RSS Feed

If you know how to get the HTML data from the right XML-element (<description> in this case) you can just strip all HTML with PHP's strip_tags

This seems to work like you want it:

$news = simplexml_load_file('http://news.google.com.kh/news?pz=1&cf=all&ned=kh&hl=en&as_scoring=r&as_maxm=4&q=html5&as_qdr=a&as_drrb=q&as_mind=6&as_minm=3&cf=all&as_maxd=5&output=rss');

foreach($news->channel->item as $item) {
    echo "<h1>" . $item->title . "</h1>";
    echo '<p>' . strip_tags($item->description) ."</p>";

No comments:

Post a Comment