How can one efficiently retrieve and display the timestamp of news articles in an RSS feed using PHP?
To efficiently retrieve and display the timestamp of news articles in an RSS feed using PHP, you can parse the XML data from the feed and extract the timestamp information from the <pubDate> element. You can then format the timestamp as needed and display it alongside the article title.
<?php
$rss = simplexml_load_file('https://example.com/news-feed.xml');
foreach ($rss->channel->item as $item) {
$title = $item->title;
$timestamp = date('Y-m-d H:i:s', strtotime($item->pubDate));
echo "<p>$title - $timestamp</p>";
}
?>
Related Questions
- What are the best practices for adjusting the box model in PHP to avoid global styling conflicts when integrating third-party components?
- What are common issues with displaying images in PHP scripts?
- What steps should be taken to ensure that PHP code is executed properly in a local environment using XAMPP?