Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?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); }
Copy Clear