note 55880 added to function.require

From: Date: Tue, 16 Aug 2005 13:42:17 +0000
Subject: note 55880 added to function.require
Groups: php.notes 
Request: Send a blank email to php-notes+get-93739@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.require.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55880 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55880&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55880&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93739) next »