views:

112

answers:

1

I am working on a small MVC "framework", which will simply provide a more organized workspace for me, as I've found I love CakePHP but only for it's organization. Now, I'm trying to replicate the layouts (which contain <?php echo $title_for_layout; ?> and <?php echo $content_for_layout; ?>,) and I'm curious how I would be able to load a mixed PHP and HTML file... save what would normally be outputted to the browser to a variable... set the variables mentioned inside the variable, and then output the layout variable and have PHP use the variables inside it to setup the layout exactly how I want it.

Any ideas?

+1  A: 

Capture the buffer output to a string with the output buffer control functions.

$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;
}

Example taken from.

altCognito
Exactly what I needed, thanks so much.
John