|  | Posted by d on 07/01/21 11:39 
"Fred Paris" <nono@nono.invalid> wrote in message news:mr5ku1dpuaiukdi9j85t8b002v5lepn8qm@4ax.com...
 > Hi
 >
 > I would like to know if the following is possible and how to do it:
 >
 > 1)
 > I have a "template" .php file on my server, say template.php.
 > It contains some PHP instructions and some HTML
 >
 > 2)
 > I also have a script, script.php
 >
 > 3)
 > When script.php runs, I want it to run php on template.php, and write
 > the resulting html output to a file.
 >
 > I need to say something like:
 >
 > <?php
 >
 > runphp (  'template.php',  'htmloutput.html' );
 >
 > ?>
 >
 > and obtain a file, htmloutput.html, with the result of php having run
 > template.php (hope I'm being clear).
 >
 > The problem is, of course, that the runphp function doesn't exist so
 > what is the way to do it?
 >
 
 function runphp($in_fn, $out_fn) {
 ob_start();
 include($in_fn);
 $c=ob_get_contents();
 ob_end_clean();
 $fp=fopen($out_fn, "wb");
 fwrite($fp, $c);
 fclose($fp);
 }
 
 That's very simple, of course.  If something isn't exactly right in how it's
 called, it'll fail most spectactularly :)  It gives you the general jist,
 though - using output buffering to capture the output of a given script, and
 then storing that output in a file.
 
 Let me know if there's something you don't understand.
 
 dave
 
 
 > Thanks
 > Fred
 >
 [Back to original message] |