get_include_contents (function from PHP.net examples) help
Posted: Thu Mar 02, 2006 1:15 pm
Right.
I've coded a templating class. It's usage is like this:
make_content_block is like this:
get_include_contents:
It doesn't work and I can't understand why. I'm not getting an unable to open stream error, I know somethings in the file (just some simple echo statements for testing), it never echo's $filename is not a valid file.
It just shows nothing.
Is it something to do with defining the function in the same class that I'm calling it from?
I've also tried replacing the include() statement in get_include_contents() with exec(file_get_contents()), but that has the same effect.
If I insert an echo msg before return contents it shows it.
If I get rid of my get_include_contents() call in my make_content_block() function and just use include it does exactly what I want but it gets output to the browser at the wrong time in my script, so it's out of place.
All I want to do is run the file given to the function and store everything thats outputted to the browser in a string instead of actually outputting it to the browser.
Anyone got any ideas for me?
Thanks.
I've coded a templating class. It's usage is like this:
Code: Select all
//...define other vars...
$template->content_include_file = 'something.php';
//...define other vars...
echo $template->make_content_block();Code: Select all
function make_content_block() {
$content_blocks1 =
'<div class="content">' . "\n";
'<p>' . "\n";
$this->get_include_contents('blocks/' . $this->content_include_file);
$content_blocks1 .=
'</p>' . "\n";
$content_blocks1 .=
'</div>' . "\n";
}
return $content_blocks1;
}Code: Select all
function get_include_contents($filename) {
if(is_file($filename)) {
ob_start();
include($filename);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
} else {
echo $filename . ' is not a valid file!';
return FALSE;
}
}It just shows nothing.
Is it something to do with defining the function in the same class that I'm calling it from?
I've also tried replacing the include() statement in get_include_contents() with exec(file_get_contents()), but that has the same effect.
If I insert an echo msg before return contents it shows it.
If I get rid of my get_include_contents() call in my make_content_block() function and just use include it does exactly what I want but it gets output to the browser at the wrong time in my script, so it's out of place.
All I want to do is run the file given to the function and store everything thats outputted to the browser in a string instead of actually outputting it to the browser.
Anyone got any ideas for me?
Thanks.