<?php
xmlDebug();
function xmlDebug(){
$url = 'https://borsen.dk/rss/profinancialtimes';
$rssXml = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
$rssXml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/');
$items = [];
foreach ($rssXml->channel->item as $itemXml) {
$itemArray = json_decode(json_encode($itemXml), true); // Convert the SimpleXMLElement to an array
// Check for the older format first (with the <image> tag)
if (isset($itemArray['image'])) {
$itemArray['thumbnail'] = $itemArray['image']['url'];
} else {
// Default to the newer format with the media:thumbnail tag
$thumbnail = $itemXml->xpath('media:thumbnail');
if ($thumbnail) {
$itemArray['thumbnail'] = (string)$thumbnail[0]['url'];
}
}
$items[] = $itemArray;
}
var_dump($items);
}