'Failed to fetch SPC data.']); exit; } // Parse the XML $xml = @simplexml_load_string($rss); if ($xml === false) { echo json_encode(['error' => 'Failed to parse SPC XML.']); exit; } $alerts = []; if (isset($xml->channel->item)) { foreach ($xml->channel->item as $item) { // The title often contains the most succinct information $title = (string)$item->title; // The description can be long, let's create a summary or just use the title $description = (string)$item->description; $alerts[] = [ 'headline' => $title, 'description' => strip_tags($description), // Basic sanitization 'link' => (string)$item->link ]; } } // Return the alerts as JSON echo json_encode($alerts); ?>