.container { display: flex; gap: 10px; } .container > div { width: 45%; height: 300px; box-sizing: border-box; } .original-box { border: 1px solid #ccc; padding: 10px; white-space: pre-wrap; overflow-y: auto; font-family: monospace; background: #fff; } textarea { width: 45%; height: 300px; box-sizing: border-box; font-family: monospace; } '; // Path to your JSON file $jsonFile = __DIR__ . '/data_alcea.json'; // Helper function to highlight differences (simple version) function highlightDiff($old, $new) { $oldWords = preg_split('/(\s+)/', $old, -1, PREG_SPLIT_DELIM_CAPTURE); $newWords = preg_split('/(\s+)/', $new, -1, PREG_SPLIT_DELIM_CAPTURE); $result = ''; $i = 0; $j = 0; while ($i < count($oldWords) && $j < count($newWords)) { if ($oldWords[$i] === $newWords[$j]) { $result .= htmlspecialchars($oldWords[$i]); $i++; $j++; } else { // Mark old words missing in new as bold $result .= '' . htmlspecialchars($oldWords[$i]) . ''; $i++; } } // Remaining old words while ($i < count($oldWords)) { $result .= '' . htmlspecialchars($oldWords[$i]) . ''; $i++; } // Note: This only highlights removed text on left side for simplicity return $result; } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_text'], $_POST['original_text'])) { // Save changes $newText = $_POST['new_text']; $originalText = $_POST['original_text']; $json = file_get_contents($jsonFile); $data = json_decode($json, true); if (!is_array($data)) { die('Invalid JSON data.'); } // Find and update the matching entry by original text foreach ($data as &$item) { foreach ($item as $date => &$entry) { if (isset($entry['value']) && $entry['value'] === $originalText) { $entry['value'] = $newText; // Save JSON file_put_contents($jsonFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); echo "
Entry updated successfully.
"; echo ""; exit; } } } echo "Original entry not found in JSON.
"; exit; } // Display diff and form when GET params present if (isset($_GET['new'], $_GET['original'])) { $new = $_GET['new']; $original = $_GET['original']; echo ''; echo 'No edit data provided. Please provide ?new=...&original=... in the URL.
"; }