I have a variable that contains an array from form data, seen below:
$option1 = explode("\n", $_POST['form1']);
I then write the array to another file:
$test = array($option1);
$file = 'test.php';
file_put_contents($file, '<?php \n\n $array=' . var_export($test, true) . ';' . '\n');
I would like to write/include a file or a large amount of code in the test.php file above to manipulate the $array. When trying the below code it just prints the contents of the include file to the current page instead of writing it:
file_put_contents($file, include('includefile.php'));
If I understood well, you would like include the code from
includefile.phpinto your test.php ?You can’t use include like that, but you should do it like that.
This will append the content from
includefile.phpinto yourtest.php