From bf197ae96bab82b8104b7f106de15809e1125300 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Tue, 20 Aug 2024 12:58:55 +0300 Subject: [PATCH] Fixes regexps --- app/pages/config.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/pages/config.php b/app/pages/config.php index f772edc..58440eb 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -11,14 +11,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { $updatedContent = $content; foreach ($_POST as $key => $value) { - - $config['platforms'][$platform_id][$key] = $value; - // search pattern for the old value - $oldValue = "/('$platform_id'\s*=>\s*\[\s*'$key'\s*=>\s*)'[^']*'/"; - // new value - $newValue = "$1'$value'"; - - $updatedContent = preg_replace($oldValue, $newValue, $updatedContent); + // Create a regex pattern to match the key-value pair for the specified platform ID + $pattern = "/((?:'[^']+'\s*=>\s*'[^']+'\s*,?\s*)*)('{$key}'\s*=>\s*)'[^']*'/s"; + // Replace using a callback to handle the match and replacement + $updatedContent = preg_replace_callback($pattern, function($matches) use ($value) { + return $matches[1] . $matches[2] . "'{$value}'"; + }, $updatedContent + ); } // check if file is writable