I am using file_get_contents() to fetch a template file featuring placeholders.
The page then uses str_replace() to insert user data into the template file, and then fwrite() to create a new file that looks like the template with the user data inserted.
Everything was working well until I changed the page to allow the user to define their own number of placeholders/fields.
I would like to use a loop within the template file to create my page.
The problem is that file_get_contents() reads the file as text before the PHP is executed.
For example,
<?php
for ($i=1; $i<=$numberoffields; $i++){
echo('{placeholder'.$i.'}');
}
?>
This prints {placeholder1} to the template page, but not until its too late.
Is there a way to do this where the above PHP loop is executed before file_get_contents()?