array('timeout' => 5))); $holidayJson = @file_get_contents($apiUrl, false, $ctx); if ($holidayJson) { $holidayData = json_decode($holidayJson, true); if (isset($holidayData['holidays'])) { foreach ($holidayData['holidays'] as $h) { $startDate = new DateTime($h['start_date']); $endDate = new DateTime($h['end_date']); $titleEn = $h['title']; $isSub = (stripos($titleEn, 'substitution') !== false || stripos($titleEn, 'observed') !== false); $name = getThaiHolidayName($titleEn); if ($isSub) { $name = 'ชดเชย' . str_replace('ชดเชย', '', $name); } for ($d = $startDate; $d <= $endDate; $d->modify('+1 day')) { $dateStr = $d->format('Y-m-d'); $holidays[$dateStr] = $name; } } } } echo json_encode(['status' => 'success', 'data' => $holidays]); } catch (Exception $e) { http_response_code(500); echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } ?>