'https://tv24.co.uk/x/channel/premier-sports-1/120/today', 'id' => 'PREMIER_SPORTS_1', 'display_name' => 'Channel 1' ], [ 'url' => 'https://tv24.co.uk/x/channel/premier-sports-2/120/today', 'id' => 'PREMIER_SPORTS_2', 'display_name' => 'Channel 2' ] ]; // Create XML structure $xml = new SimpleXMLElement(''); foreach ($channels as $channelInfo) { // Fetch HTML content from the URL $html = file_get_contents($channelInfo['url']); // Load the HTML into a DOMDocument $dom = new DOMDocument; @$dom->loadHTML($html); $xpath = new DOMXPath($dom); // Get the current date $currentDate = date('Ymd'); // Extract data from the HTML $items = $xpath->query('//ul[@class="section-items t12 with-ended"]/li'); $programs = []; foreach ($items as $item) { $time = $xpath->query('.//span[@class="time"]', $item)->item(0)->nodeValue; $title = $xpath->query('.//h3', $item)->item(0)->nodeValue; $desc = $xpath->query('.//span[@class="desc"]', $item)->item(0)->nodeValue; $additionalDesc = $xpath->query('.//p', $item)->item(0)->nodeValue; // Convert time to 24-hour format $startTime = date('His', strtotime($time)); // Combine date and time in the specified format $startDateTime = $currentDate . $startTime . ' +0000'; // Add program to the list $programs[] = [ 'start' => $startDateTime, // Change the format of start date and time 'title' => $title, 'desc' => $desc . ' ' . $additionalDesc, ]; } // Add channel and programs to the XML $channel = $xml->addChild('channel'); $channel->addAttribute('id', $channelInfo['id']); $channel->addChild('display-name', $channelInfo['display_name']); foreach ($programs as $program) { if (!empty($program['title'])) { $programme = $channel->addChild('programme'); $programme->addAttribute('start', $program['start']); $programme->addChild('title', $program['title']); $programme->addChild('desc', $program['desc']); } } } // Save the XML to a file $xml->asXML('output1.xml'); // Print a success message //echo "XML exported successfully to output.xml."; ?>