I need to replace a line in a file.php.
I need to replace a value of a variable of a file.php, yet I can get the desired line, take the value of the variable but do not know how to replace the whole line.
Example:
<?php
$archive = file('Library/config/PaymentConfig.php'); // transforms the content into an array where each line is a position
$valueLine = $archive[10]; // $environment = 'production';
function getEnvironment($valueLine){
$removecharacters = array('$environment = ', "'", ';');
return str_replace($removecharacters, '', urldecode($valueLine)); // returns only the value of the variable
}
if (getEnvironment($valueLine) == $myValue) { // $myValue = production or sandbox
// Here I need to replace the line
// For $environment = 'production'; or $environment = 'sandbox';
}
?>