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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // To fetch content from bitsontherun $data = new SimpleXmlElement($content); foreach($data- >channel- >item as $entry) { if ($media = $entry- >children('media', TRUE)) { $src = $play_attributes['url']; if ($media- >content- >thumbnail) { $attributes = $media- >content- >thumbnail- >attributes(); $imgsrc = (string)$attributes['url']; echo "<img src="".$imgsrc."" alt="" />"; } } $pub_date= explode("-",$entry- >pubDate); } |
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.