I am able to choose a single line of a file(eg. dummy.php) and replace it with a text stored in a variable, called $currentdate but I want to choose several lines and replace them with several variables. For example:
$site_name in 2nd line,
$URL in 4th line,
$protocol in line 6,
$author in line 8,
$description in line 10
And
$currentdate in line 12.
I've made this code, which replaces second line:
$currentdate = date('d F Y');
$filename = getcwd() . "/dummy.php";
$date_line = 1;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$date_line] = "$currentdate";
file_put_contents( $filename , implode( "\n", $lines ) );
I repeat the question, how to add several variables in several lines of that fine? Example variables and line numbers are given in this question. Also, I've made a code, but I don't know, whether it will work or not. I can't try adding this code to my project files, because I'm scared of being my code worse and disabling other codes, which are also stood in that page. Here is the non-tested code:
$site_name_line = 1;
$URL_line = 3;
$protocol_line = 5;
$author_line = 7;
$description_line = 9;
$currentdate_line = 11;
$lines = file( $filename , FILE_IGNORE_NEW_LINES );
$lines[$site_name_line] = "$site_name";
$lines[$URL_line] = "$URL";
$lines[$protocol_line] = "$protocol";
$lines[$author_line] = "$author";$lines[$description_line] = "$description";$lines[$currentdate_line] = "$currentdate";
file_put_contents( $filename , implode( "\n", $lines ) );