I ‘ve used the following code to create PHP file dynamically
$value = 5;
$file = $compname.'.php';
$file_pointer = fopen( $file, 'w' );
$string = '<?php $var = '. $value .' ?>';
fwrite( $file_pointer, $string );
fclose($file_pointer);
include($file);
echo $var;
Is it possible to insert template in that php file and the file name conatins spaces is it possible to remove those space and add “-”
As @ianhales mentioned, you can use str_replace() for replacing white-spaces in the name. If I understand your question correctly, you want to use a template file to generate the contents of the PHP file. To do that, I would do the following.
Create template.txt file
Then you use the template: