Fixes regexps

main
Yasen Pramatarov 2024-08-20 12:58:55 +03:00
parent 2bbc4af068
commit bf197ae96b
1 changed files with 7 additions and 8 deletions

View File

@ -11,14 +11,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$updatedContent = $content; $updatedContent = $content;
foreach ($_POST as $key => $value) { foreach ($_POST as $key => $value) {
// Create a regex pattern to match the key-value pair for the specified platform ID
$config['platforms'][$platform_id][$key] = $value; $pattern = "/((?:'[^']+'\s*=>\s*'[^']+'\s*,?\s*)*)('{$key}'\s*=>\s*)'[^']*'/s";
// search pattern for the old value // Replace using a callback to handle the match and replacement
$oldValue = "/('$platform_id'\s*=>\s*\[\s*'$key'\s*=>\s*)'[^']*'/"; $updatedContent = preg_replace_callback($pattern, function($matches) use ($value) {
// new value return $matches[1] . $matches[2] . "'{$value}'";
$newValue = "$1'$value'"; }, $updatedContent
);
$updatedContent = preg_replace($oldValue, $newValue, $updatedContent);
} }
// check if file is writable // check if file is writable