Home
Miramar Beach Rental
Destin Beach Rental
Beach & Weather
Things to Do
🏝
Activities & Attractions
🏖
Beaches & Nature
🍴
Dining & Restaurants
💸
Free & Low-Cost Ideas
📖
Recent Guides
🛍
Shopping
❤
Things to Do for Couples
👦
Things to Do with Kids
🌧
Things to Do When It Rains
🧲
Trip Planner
📅
Upcoming Events
"forbidden"]); exit; } $path = realpath(__DIR__ . "/../../data/events-cache.json"); if (!$path) { echo json_encode(["error" => "path not resolved", "dir" => __DIR__]); exit; } $raw = file_get_contents($path); if ($raw === false) { echo json_encode(["error" => "read_failed"]); exit; } $size = strlen($raw); $first64hex = bin2hex(substr($raw, 0, 64)); $last32hex = bin2hex(substr($raw, max(0, $size-32))); if (mb_check_encoding($raw, "UTF-8")) { $json = json_decode($raw, true); echo json_encode(["status" => "already_valid_utf8", "size" => $size, "valid_json" => is_array($json), "event_count" => is_array($json) ? count($json["events"] ?? []) : null]); exit; } $fixed = null; $usedEncoding = null; foreach (["ISO-8859-1","Windows-1252","UTF-16","UTF-16LE","UTF-16BE"] as $enc) { $attempt = @mb_convert_encoding($raw, "UTF-8", $enc); if ($attempt && mb_check_encoding($attempt, "UTF-8") && strlen($attempt) > 100) { $json = json_decode($attempt, true); if (is_array($json)) { $fixed = $attempt; $usedEncoding = $enc; break; } } } if (!$fixed) { $attempt = iconv("UTF-8", "UTF-8//IGNORE", $raw); if ($attempt && strlen($attempt) > 100) { $json = json_decode($attempt, true); if (is_array($json)) { $fixed = $attempt; $usedEncoding = "iconv-ignore"; } } } if (!$fixed) { echo json_encode(["status" => "unfixable", "size" => $size, "first64hex" => $first64hex, "last32hex" => $last32hex]); exit; } $tmp = $path . ".tmp." . bin2hex(random_bytes(4)); if (file_put_contents($tmp, $fixed, LOCK_EX) === false) { echo json_encode(["status" => "write_failed"]); exit; } if (!rename($tmp, $path)) { @unlink($tmp); echo json_encode(["status" => "rename_failed"]); exit; } $json = json_decode($fixed, true); echo json_encode(["status" => "fixed", "encoding_used" => $usedEncoding, "original_size" => $size, "fixed_size" => strlen($fixed), "event_count" => is_array($json) ? count($json["events"] ?? []) : null, "first64hex" => $first64hex]);