\nHTML
\nJSON
\nText\n\n"; exit(); } return $fmt; } function _get_fmt(): string { if (!empty($_GET['format'])) return $_GET['format']; $fmts = []; foreach (explode(',', $_SERVER['HTTP_ACCEPT']) as $acc) { $acc = explode(';', trim($acc)); $q = 1; if (sizeof($acc) > 1) { $qv = trim($acc[1]); if (str_starts_with($qv, 'q=')) { $q = (double)substr($qv, 2); } } $fmts[trim($acc[0])] = $q; } arsort($fmts, SORT_NUMERIC); array_filter($fmts, function($k) { return str_contains($k, '/json') || $k === 'text/html' || $k === 'text/plain' || str_contains($k, 'text/*'); }); $type = sizeof($fmts) > 0 ? array_key_first($fmts) : null; if (str_contains($type, '/json')) { return 'json'; } else if ($type === 'text/html') { return 'html'; } else { return 'text'; } }