<?php declare(strict_types=1); header('Content-Type: application/json; charset=utf-8'); $url = 'https://prayer-times-pinneberg.vercel.app/'; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT => 20, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_USERAGENT => 'Mozilla/5.0 (PrayerTimes PHP Scraper)', ]); $html = curl_exec($ch); if ($html === false) { http_response_code(500); echo json_encode([ 'error' => 'Failed to fetch page', 'details' => curl_error($ch), ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); curl_close($ch); exit; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode >= 400) { http_response_code(500); echo json_encode([ 'error' => 'Remote server returned an error', 'status_code' => $httpCode, ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; } libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->loadHTML('<?xml encoding="utf-8" ?>' . $html); $xpath = new DOMXPath($dom); foreach ($xpath->query('//script|//style|//noscript') as $node) { $node->parentNode?->removeChild($node); } $text = $dom->textContent ?? ''; $text = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $text = preg_replace('/\s+/u', ' ', $text); $text = trim((string) $text); $patterns = [ 'fajr' => '/(?:İmsak|Imsak)[^\d]{0,40}(\d{2}:\d{2})/u', 'dhuhr' => '/(?:Öğle|Ogle)[^\d]{0,40}(\d{2}:\d{2})/u', 'asr' => '/(?:İkindi|Ikindi)[^\d]{0,40}(\d{2}:\d{2})/u', 'maghrib' => '/(?:Akşam|Aksam)[^\d]{0,40}(\d{2}:\d{2})/u', 'isha' => '/(?:Yatsı|Yatsi)[^\d]{0,40}(\d{2}:\d{2})/u', ]; $result = []; foreach ($patterns as $name => $pattern) { if (preg_match($pattern, $text, $matches)) { $result[$name] = $matches[1]; } else { $result[$name] = null; } } echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
You have javascript disabled. You will not be able to edit any code.