Get RSS Feed - Php

How to get rss feed using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

This php code can be used as RSS parser. Here, give the desired link in the "get_rss" function and run to display the rss information.

<?php function get_rss($url) { error_reporting(0); $rss = new DOMDocument(); $url = utf8_encode($url); $rss->load($url); $rss_data = array(); foreach ($rss->getElementsByTagName('item') as $tag) { $item = array ( 'title' => $tag->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $tag->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $tag->getElementsByTagName('link')->item(0)->nodeValue, ); array_push($rss_data, $item); } $limit = 10; for($a=0;$a<$limit;$a ) { $title = str_replace(' &', ' ampamp; ', $rss_data[$a]['title']); $link = $rss_data[$a]['link']; $description = $rss_data[$a]['desc']; echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong></br>'; echo '<p>'.$description.'</p>'; } } echo get_rss('https://www.fancygreetings.com/rss.xml'); ?>

Tags


Ask Questions

Ask Question