'); $p2 = strpos($html, ''); if ($p1 === false || $p2 === false) { header('Status: 404'); header('Content-Length: 22'); echo "{\"error\":\"not found\"}\n"; exit; } $html = substr($html, $p1 + 6, $p2 - $p1 - 6); $data = []; preg_match_all('@
\s*
]*?>\s*(.*?)\s*
\s*
@s', $html, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $data[$m[1]] = trim(preg_replace('/\s*\n\s*/', "\n", html_entity_decode(preg_replace('/<.*?>/', '', str_replace('
', "\n", preg_replace('/\s+/', ' ', trim($m[2]))))))); } $certRows = []; preg_match_all('@\s*\s*(.*?)\s*\s*\s*(.*?)\s*\s*\s*(.*?)\s*\s*\s*(.*?)\s*\s*@s', $html, $matches, PREG_SET_ORDER); foreach ($matches as $m) { $cert = []; foreach (array_splice($m, 1) as $s) { $cert[] = trim(preg_replace('/\s*\n\s*/', "\n", preg_replace('/<.*?>/', '', str_replace('
', "\n", preg_replace('/\s+/', ' ', trim(html_entity_decode($s))))))); } $certRows[] = $cert; } $lines = explode("\n", $data['Address']); [$cc, $_, $postalCode, $city] = explode(' ', $lines[2], 4); $certs = []; foreach ($certRows as $row) { [$nr, $lang] = explode('(', $row[1], 2); [$from, $to] = explode(' - ', $row[3], 2); $certs[] = [ 'nr' => trim($nr), 'language' => substr($lang, 0, 2), 'pdfUrl' => $row[0], 'type' => $row[2], 'validFrom' => date('Y-m-d', strtotime($from)), 'validUntil' => date('Y-m-d', strtotime($to)), ]; } [$authCode, $authName] = explode(' ', $data['Certification body'], 2); echo jenc([ 'id' => $id, 'idNr' => $data['Operator ID'] ?? null, 'name' => $lines[0], 'address' => $lines[1], 'postalCode' => $postalCode, 'city' => $city, 'countryCode' => $cc, 'authority' => ['code' => $authCode, 'name' => $authName], 'url' => $base, 'originUrl' => $url, 'certificates' => $certs, ]); exit; } $source_groups = [ ['', '0892fdd7-6649-cb3b-75ef-a60649cfebfd'], ['', 'fde4ccef-0f36-4db9-9f2f-9bb6009c872a'], ['', '8e6d20d3-6bbe-c7ae-7a77-fb7fa80ee291'], ['', '830b3bd7-f1da-e20e-300d-e561bfb8205b'], ['', 'ed025d59-056f-ffd0-79e0-05348fe88d59'], ['', '95d536c8-c869-9f72-1bce-4256a2a4ce49'], ['', 'bef6b49a-3186-ba7f-fffb-281bfb4ca2d2', 'fc7a0cc3-c4b4-a4fb-5b7e-5cf9b68ed198', '9aecd829-8f3c-6829-449f-9cb511e0c1ff', 'e7a7089b-0fd7-60b9-48af-c0988a90ec37', '63d570d8-0ab2-b793-fe11-62e0777e4236' ], ]; $country = [ 'AT' => 'a1e51f85-27b5-a1e3-65f7-561569884d38', 'DE' => '1be4d468-ba47-08f1-f048-f45869af856f', ][$_GET['country'] ?? null] ?? null; $postalCode = $_GET['postalCode'] ?? null; $name = $_GET['name'] ?? null; $idNr = $_GET['idNr'] ?? null; if ($country === null) { header('Status: 400'); header('Content-Length: 88'); echo "{\"error\":\"bad request\",\"message\":\"The 'country' request URL query parameter is required\"}\n"; exit; } $data = []; $url = "https://www.bioc.info/search/producerSearchQuery?search[name]=" . urlencode($name) . "&search[citycode]=" . urlencode($postalCode) . "&search[operatorId]=" . urlencode($idNr) . "&search[country]=$country"; $m = curl_multi_init(); $requests = []; foreach ($source_groups as $group) { $s = curl_init($url . implode('&sources[]=', $group)); $requests[] = $s; curl_setopt($s, CURLOPT_RETURNTRANSFER, true); curl_multi_add_handle($m, $s); } $running = 1; do { curl_multi_exec($m, $running); } while ($running); foreach ($requests as $r) { curl_multi_remove_handle($m, $r); } curl_multi_close($m); foreach ($requests as $s) { if (($json = curl_multi_getcontent($s)) === false) { header('Status: 500'); header('Content-Length: 34'); echo "{\"error\":\"internal server error\"}\n"; exit; } $res = json_decode($json, true)['results']; foreach ($res as $r) { $data[$r['id']] = $r['row']; } } header('Content-Type: application/json; charset=UTF-8'); $first = true; echo "{\"data\":[\n"; foreach ($data as $id => $row) { if (!$first) echo ",\n"; $row = explode("') + 1), 2); echo " "; echo jenc([ 'id' => $id, 'name' => substr($row[0], strrpos($row[0], '>') + 1), 'postalCode' => substr($row[1], strrpos($row[1], '>') + 1), 'city' => substr($row[2], strrpos($row[2], '>') + 1), 'authority' => ['code' => $auth[0], 'name' => $auth[1]], 'url' => "$base/$id", ]); $first = false; } echo "\n]}\n";