Back to Top

How to Read an RSS Feed With PHP

Recently I had a project that involved reading RSS feeds.I have created a simple PHP Script to read RSS Feed.

I have used simple XML element to read the feeds and then breaking it down based on structure. Sometimes it has been hard to deal with the some non-standard feeds.So today I am going to show you how you can extract RSS XML feed data.

Here, I have used bitsontherun host and stream videos and to display information of videos. I have used RSS XML feed and only extracted the values I needed, but you can extract any feed data with below code.

Now, let’s move to the coding part.Here, I have used thumbnail and date to extract from feed and getting display on the screen.


$content = file_get_contents("http://content.bitsontherun.com/feeds/CHANNEL-TEMPLATE.rss");

// To fetch content from bitsontherun
$data = new SimpleXmlElement($content);
foreach($data- >channel- >item as $entry)
{
	if ($media = $entry- >children('media', TRUE)) {
		$attributes = $media- >content- >attributes();
		$src = $play_attributes['url'];
		if ($media- >content- >thumbnail) {
			$attributes = $media- >content- >thumbnail- >attributes();
			$imgsrc = (string)$attributes['url'];
			echo "";
		}
	}
$pub_date= explode("-",$entry- >pubDate);
echo date('F d,Y',strtotime(trim($pub_date[0])));;

}

Also Read:

Introduction to Transient API in WordPress
Parsing an RSS Feed with WordPress
To parse CSV Data in PHP

In a lot of conditions, It may be easier to use a simple XML element, but I recommend this function when you need the string output.

That’s it.I hope this post will help you. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

JQuery Animation effects

Posted on 6 years ago

Bhumi

How To Create a Temporary File in PHP

Posted on 6 years ago

Bhumi

How to use WebService in PHP

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 3 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 4 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 4 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 5 years ago

Bhumi