Read RSS feed of website (blog) using php

This is tutorial about reading/fetching RSS feed of blog using simple php function, There is a function called simplexml_load_file(), By which we can easily render the xml file and read it into php array format. You must read the official document of Simple XML Parser . If you want to perform action on XML files

For fetching RSS feed of website you need to enable RSS feed first in your website after that, You’ll put RSS Feed URL in my php function which i am going to show you and see the result, Using below function you can easily add your blog articles into your website news ticker.

First create a simple RSS Feed reader function in php using using XML parser functions.

function getRssFeed($rssFeedUrl) {
  $rssFeed = array();	
  if(!empty($rssFeedUrl)) {
	foreach ($rssFeedUrl->channel->item as $feedItem) {
	$data['title'] = $feedItem->title;
	$data['pubDate'] = $feedItem->pubDate;
	$data['description'] = implode(' ', array_slice(explode(' ', $feedItem->description), 0, 40));
	array_push($rssFeed, $data);
   return $rssFeed;

After that call this function where you want to display your feeds. And design a simple layout for your feeds.

<div style="width:60%; margin:0 auto; border: 1px solid">
<h1>Rss Feed Using PHP</h1>
<div id="rss" style="padding-left:10px; padding-right:10px;">
$rssFeedUrl = simplexml_load_file("");
$rssResult = getRssFeed($rssFeedUrl);
foreach($rssResult as $rss) { 
<h4><?= $rss['title'] ?> </h4>
<p><?= $rss['description'] ?><br/>
<b><?= $rss['pubDate'] ?></b>
<?php } ?>

See live demo and download source code.



If you like this post please don’t forget to subscribe my public notebook for more useful stuff

Posted in PHP