my question is similiar like this : Replace string in text file using PHP
but i want replace by spesification variable
for example, i have already file exist .env
variable_1=data_2021
variable_99=data_2050
variable_991=data_2061
so how i can replace by spesificiation name variable for the value ?
i want replace data_2050
with data_2051
without change on other text where the variable is variable_99
$myfile = fopen("../../.env.securepay", "w") or die("Unable to open file!");
fwrite($myfile, 'variable_99='.$value);
fclose($myfile);
// $myfile = fopen("../../.env", "w") or die("Unable to open file!");
// fseek($myfile, 0);
// fwrite($myfile, 'variable_99 ='.$value);
// fclose($myfile);
// $oldMessage = 'variable_99';
// $deletedFormat = '';
// //read the entire string
// $str=file_get_contents('../../.env.securepay');
// //replace something in the file string - this is a VERY simple example
// $str=str_replace($oldMessage, $deletedFormat, $str);
// //write the entire string
// file_put_contents('../../.env', $str);
above code just remove all the content file .env
and re added variable_99=value