I have a configuration file with the following contents:
[settings]
temp_path = ""
encode_to_UTF8 = "false"
language = "en-US"
paper_size = "A4"
[license]
code = "8cf34efe0b57013668df0dbcdf8c82a9"
I need to replace the key between the code = "*" with something else, how can I do this with preg_replace ()? The configuration file contains more parameters, so I only need to replace the key between
code = "*replace me*"
It should be something like this:
$licenseKey = 'newLicenseKey';
$configFileContent = file_get_contents(configFile.ini);
$configFileContent = preg_replace('/(code = ")(.*)(")/', $licenseKey, $configFileContent);
But this replaces the entire string with only the new licenseKey.
How can i do this?
source
share