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
- How can PHP be used to maintain referential integrity and trigger stored procedures when handling contact data in a web application?
- How can beginners effectively communicate their coding issues in PHP forums to receive helpful responses?
- What best practices should be followed to ensure proper error handling and debugging in PHP scripts, especially when dealing with output issues?