Showing Posts From

Rss parser php

How to make a news aggregator website

How to make a news aggregator website

Hi Geeks, I am Sharing you the code for reading a rss feed using php script. Following are the Steps to make a news aggregator website using rss reader in php Step 1: Create a form having Rss Urls in select box as following Choose category :Select India News World News Science NewsStep 2. Php code to recieve the submitted post and rss url. and get the rss output in object and parse the feed or rss using the dom document class and accessing the properties as following: Search Result for rss url:'.$_POST['rssurl'].''; $rssurl=$_POST['rssurl']; $rss = new DOMDocument(); $rss->load($rssurl); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for($x=0;$x'.$title.''; echo 'Posted on '.$date.''; echo ''.$description.''; } } ?>Final Complete Code: Choose category :Select India News World News Science Newsif(isset($_POST['rssurl'])) { echo 'Search Result for rss url:'.$_POST['rssurl'].''; $rssurl=$_POST['rssurl']; $rss = new DOMDocument(); $rss->load($rssurl); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for($x=0;$x<$limit;$x++) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo ''.$title.''; echo 'Posted on '.$date.''; echo ''.$description.''; } } ?> Conclusion : Select your category and click on go button and you will see the fetched news from rss feed. read rss using php script