note 39996 modified in function.ob-get-contents by aidan

From: Date: Sat, 19 Jun 2004 07:43:06 +0000
Subject: note 39996 modified in function.ob-get-contents by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71317@lists.php.net to get a copy of this message
want to use templates to write files from a php script? here's one way: <?php /*set whatever values will be printed in the template*/ $var1 = "some value"; $var2 = "some other value"; /*start the output buffering*/ ob_start(); /*include the tempate file*/ require("template.inc"); /*get the contenst of the output buffer*/ $data = ob_get_contents(); /*write the contents to a file*/ $fp = fopen("somefile.txt","w"); fwrite($fp,$data); fclose($fp); /*clear the output buffer*/ ob_clean(); /*display some other page - like "you have successfully written a file" or something*/ require("return_url.php"); ?> too easy!! --was-- want to use templates to write files from a php script? here's one way: /*set whatever values will be printed in the template*/ $var1 = "some value"; $var2 = "some other value"; /*start the output buffering*/ ob_start(); /*include the tempate file*/ require("template.inc"); /*get the contenst of the output buffer*/ $data = ob_get_contents(); /*write the contents to a file*/ $fp = fopen("somefile.txt","w"); fwrite($fp,$data); fclose($fp); /*clear the output buffer*/ ob_clean(); /*display some other page - like "you have successfully written a file" or something*/ require("return_url.php"); too easy!! http://php.net/manual/en/function.ob-get-contents.php

« previous php.notes (#71317) next »