PHP: Capture Included File Contents to Variable
No Comments
by Byron Bennett / July 20th, 2008
I banged my head against several walls on this a while back and finally gave up. Today I found this post over at bin-co.com describing how to capture the contents of an include file to a variable. Here’s the code…thanks Binny!
|
|
|
| The code:
$string = getIncludeContents('template.php');
function getIncludeContents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
Filed under: Miscellany
