Hello everyone.
I'm looking for a script/function that will allow me to use PHP to create another PHP page based on a template. I want the script to be able to stick some variables into a template, then generate a static PHP page on my server. I know I can use PHP to make a directory, but can I create a template-based file and put it in that directory?
Thanks
Tom
Create new php page using PHP
Moderator: General Moderators
-
Tomcat7194
- Forum Commoner
- Posts: 48
- Joined: Mon Jul 31, 2006 1:34 pm
Sure. php doesn't care what it's wrinting to a file, it's just a string.
Simple example
Simple example
Code: Select all
<?php
$rand = rand(10,99);
$php = <<< eot
<?php
echo $rand;
?>
eot;
file_put_contents('test.create.php', $php);
?>if you're using a version of php prior to 5, you'll need to use fwrite() (there is an example on that page that shows how) to write your file instead of file_put_contents()