note 55880 deleted from function.require by victor

From: Date: Tue, 16 Aug 2005 14:44:36 +0000
Subject: note 55880 deleted from function.require by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93742@lists.php.net to get a copy of this message
Note Submitter: topera at gmail dot com ---- If you don't want that a file sends output when you use require(), use this function... <?php function require_silent($file, $once=false) { // all variables can be read here extract($GLOBALS); // stop to send output to client ob_start(); // run file if ($once) { require_once($file); } else { require($file); } // get data from ob (output buffer) $msg = ob_get_contents(); // restart to send data to client ob_end_clean(); return $msg; } ?> Example of use: <?php // run file $a = require_silent("b.php"); // now I want to echo... echo $a; // obs: require("b.php") do the same ?> Another example (usefull) <?php $my_var_used_in_my_email = "foobar"; $msg = require_silent("my_email.php"); mail("a@a", "test", $msg); ?> This function is != from file() or fgets() because it interprets the file, not only read. :) Rafael Pereira dos Santos

« previous php.notes (#93742) next »