$newValue) { // we look for 'option' => value // option is always in single quotes // value is without quotes, because it could be true/false $pattern = "/(['\"]{$key}['\"]\s*=>\s*)([^,]+),/"; // prepare the value, make booleans w/out single quotes if ($newValue === 'true') { $replacementValue = 'true'; } elseif ($newValue === 'false') { $replacementValue = 'false'; } else { $replacementValue = var_export($newValue, true); } // value replacing $config_contents = preg_replace($pattern, "$1{$replacementValue},", $config_contents); } // write the new config file if (!file_put_contents($config_file, $config_contents)) { return "Failed to write the config file \"$config_file\"."; } return true; } } ?>