PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

Share:

PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage. Have you ever wanted to display posts of other websites in your blog, at least a piece of the title and description? If your answer is yes, and to this day still have not found a way how to do it. In this tutorial will help you to get a solution, that is by showing RSS Feeds / Sitemap of any website that you want such as from BBC News, Now York Times website, or wordpress and blogger platform. As a condition, you have to know the address of the sitemap / RSS Feeds website.
PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

Ok, let’s start discussing how to display RSS feeds / Sitemap of other websites in your webpage easily. Read the tutorial below :

Download Now PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

To read and parse xml files into html format, we will use the simplexml_load_file() function. A simple php script to display RSS feeds / sitemap is as bellow :

<?php
$xml=simplexml_load_file("sitemap-or-rss-feed.xml");
print_r($xml);
?>

The result is an array so that each title and description still inside the array. So as title, description and url of the post can be displayed, we will simply call the existing data on the channel. To do so, we need foreach ($xml->children() as $child) function. Which,

children() = channel->item
$child = $item

So, the php script to be foreach ($xml->channel->item as $item).

Learn more about the php script to display RSS Feed / sitemap from other websites, please see below. Copy into your webpage, then save.

<html>
<title> PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage | Tutorial.World.Edu </title>
<head>
<style>
.display-rss-feed{
width:600px;
margin-left:200px;
border:1px;
color:#959595;
padding:0px 20px 0px 20px;
font-family: "Open Sans","Tahoma","Verdana","Arial", sans-serif;
background:#eeeeee;
}
h1 {
width:600px;
margin-left:200px;
color:#626262;
text-align:center;
}

a{
text-decoration:none;
font-size:17px;
border-bottom-style:dotted;
color:#626262;
}
</style>
<body>
<?php
echo '<h1> <a href="http://tutorial.world.edu/web-development/php-script-display-rss-feed-sitemap-other-website-webpage/">PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage</a> <a href="http://tutorial.world.edu">Tutorial.World.Edu</a> </h1>';
$xml=simplexml_load_file("http://tutorial.world.edu/feed/");
foreach ($xml->channel->item as $item) {
    $title = (string) $item->title; // Title Post
    $link   = (string) $item->link; // Url Link
    $description = (string) $item->description; //Description Post
echo '<div class="display-rss-feed"><a href="'.$link.'" target="_blank" title="" >'.$title.' </a><br/><br/>';
echo $description.'<hr></div>';
 }
?> 
</body>
</html>

Note, you can replace the address of the RSS Feed above with the RSS Feed address of the website you want, including your own website.

In the browser, the result would look like the following :
PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage PHP Script To Display RSS Feed / Sitemap From Other Website To Your WebpageIt’s easy and it takes a lot of time. Please try and good luck 🙂
Thanks for reading PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

[Tutorial.World.Edu]

4 thoughts on “PHP Script To Display RSS Feed / Sitemap From Other Website To Your Webpage

Leave a Reply

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