Not sure if this helps, I used file_put_contents() below. You may need to use fopen,fwrite,fclose depending upon the version of PHP you're using.
PHP Code:
if( ($header_template = file_get_contents('header.php.templ')) === FALSE) { echo "Read Error"; die; }
/* If you need to read in more files, such as a footer, it's the same.. */
if( ($footer_template = file_get_contents('footer.php.templ')) === FALSE) { echo "Read Error"; die; }
/* Do your variable replacements using regular expressions or what have you on the template variables here and store the result in $content -- that is if that is what you're trying to do. */
if(file_put_contents("$dt/$name", $content)===FALSE) { echo "Error!"; die; }
/* If you need to append other data to your $dt/$name file, you can still use file_put_contents() */
file_put_contents("$dt/$name", 'Hello, World!', FILE_APPEND); file_put_contents("$dt/$name", $footer_content, FILE_APPEND);
Most programs I see like this are run-time, so you'd be displaying the output instead of storing it to a file. In that case, output buffering may be important. I use scripts similar to the above for CLI side "compiling" of sites to update modified headers, or update copyright dates, cron tasks for scanning broken links, etc..
|