Home » Ask (Forum) » Display RSS Feed Image using PHP

Question

In this tutorial, I will show to you How to display RSS Feed Image using PHP.

<?php
	$rss = new DOMDocument();
	$rss->load('http://bikinwebsite.com/feed/');
	
	$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 = 3; // set the number of post do you want to display.
	for($x=0;$x<$limit;$x++) {
		$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
		$link = $feed[$x]['link'];
		$description = $feed[$x]['desc'];
		$description = substr($description, 0, 280); // limit desc - remove this line if you don't want to limit the desc.
		$date = date('l F d, Y', strtotime($feed[$x]['date']));
		echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
		echo '<small><em>Posted on '.$date.'</em></small></p>';
		echo '<p>'.$description.'</p>';
	}
?>

Note:
1. You can limit the number of text in description.
2. You must change the 3rd line with your site url feed.
3. You can change the date format.
4. You can limit the number of post. Change this line:

$limit = 3;

Good luck!

Jul 29, 2016 (4 months ago) - Posted by No Comments

Your Answer

Your email address will not be published. Required fields are marked *