![Obrazek](https://i.imgur.com/6jQeZV4.png)
Kod:
Kod: Zaznacz cały
<?php
$rss_feed_url = 'https://feeds.bbci.co.uk/news/world/rss.xml';
$options = [
'http' => [
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:97.0) Gecko/20100101 Firefox/122.0', // default useragent
],
];
$context = stream_context_create($options);
$feed_contents = file_get_contents($rss_feed_url, false, $context);
if ($feed_contents !== false) {
$feed = simplexml_load_string($feed_contents);
if ($feed) {
$counter = 0;
foreach ($feed->channel->item as $item) {
if ($counter < 5) {
$title = $item->title;
$link = $item->link;
$description = $item->description;
$pubDateUTC = new DateTime($item->pubDate, new DateTimeZone('UTC'));
$pubDateUTC->setTimezone(new DateTimeZone('Europe/Warsaw'));
$pubDateLocal = $pubDateUTC->format('H:i');
echo '<div class="news-item">';
echo '<div class="news-date">' . $pubDateLocal . ' <span class="news-title"> <a href="' . $link . '" target="_blank">' . $title . '</a> </span></div>';
echo '</div>';
$counter++;
} else {
break;
}
}
} else {
echo 'Błąd ładowania kanału RSS.';
}
} else {
echo 'Błąd pobierania danych z kanału RSS.';
}
?>
Dla przykładu RSS BBC, ale powinno przyjąć każdy inny RSS.