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; } $itemContent = $items[0] ?? []; $key = "image|url"; $keys = explode("|", $key); for ($i=0; $i < count($keys); $i++) { $itemContent = $itemContent[$keys[$i]] ?? ""; if (!is_array($itemContent)) { $output = $itemContent; break; } } if ($img) { $output = sprintf( '<div class="et_pb_module et_pb_image"> <span class="et_pb_image_wrap "> <img src="%1$s" alt="" title=""> </span> </div>', $output ); } var_dump($items); }
Copy Clear