
<?php
// URL of the RSS feed
$rssFeedUrl = 'https://solveforce.com/rss';
// Load the RSS feed
$rss = simplexml_load_file($rssFeedUrl);
// Check if the feed was loaded successfully
if ($rss) {
// Retrieve and display the feed information
echo "Title: " . $rss->channel->title . "<br>";
echo "Description: " . $rss->channel->description . "<br><br>";
// Iterate over the feed items
foreach ($rss->channel->item as $item) {
// Retrieve and display the item details
echo "Title: " . $item->title . "<br>";
echo "Link: " . $item->link . "<br>";
echo "Description: " . $item->description . "<br><br>";
}
} else {
// Display an error message if the feed couldn't be loaded
echo "Failed to load the RSS feed.";
}
In the example, we retrieve and display the title and description of the RSS feed itself ($rss->channel->title
and $rss->channel->description
) as well as the title, link, and description of each individual item in the feed.
If there’s an error loading the feed, we display a simple error message.
Below is where the script is working.