'error', 'message' => 'Nie udało się pobrać taksonomii Google.' ], JSON_UNESCAPED_UNICODE); exit; } // fallback – stary cache (lepsze to niż nic) readfile(TAXONOMY_CACHE_FILE); exit; } // parsowanie TXT -> tablica {id, text} $list = []; $lines = explode("\n", $txt); foreach ($lines as $line) { $line = trim($line); if ($line === '') { continue; } // format linii: 2271 - Health & Beauty > Personal Care > Cosmetics $parts = explode(' - ', $line, 2); if (count($parts) === 2) { $list[] = [ 'id' => trim($parts[0]), 'text' => trim($parts[1]), ]; } } $response = [ 'status' => 'ok', 'categories' => $list, ]; // zapisujemy cache na serwerze $dir = dirname(TAXONOMY_CACHE_FILE); if (!is_dir($dir)) { @mkdir($dir, 0775, true); } file_put_contents(TAXONOMY_CACHE_FILE, json_encode($response, JSON_UNESCAPED_UNICODE)); // i zwracamy do frontu echo json_encode($response, JSON_UNESCAPED_UNICODE);