How to display RSS Feeds using PHP?

<?php
$html = "";
$url = "https://www.kdnuggets.com/feed";
//https://www.sciencedaily.com/rss/matter_energy/engineering.xml
$xml = simplexml_load_file($url);

//Displaying latest 10 Feeds
for($i = 0; $i < 10; $i++){
    $title = $xml->channel->item[$i]->title;
    $link = $xml->channel->item[$i]->link;
    $description = $xml->channel->item[$i]->description;
    $pubDate = $xml->channel->item[$i]->pubDate;    

    $html .= "<a href='$link'><h3>$title</h3></a>";
    $html .= "$description";
    $html .= "<br />$pubDate<hr />";
}
echo $html;
?>

Comments