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.
See live demo and download source code.