Forum Moderators: coopster
I used to program in HTAG before, and there including a file was like executing a function. It simply returned the text output of that file. In PHP the include and require functions/operators only return status codes.
I needed a different functionality for a simple skinning system. Basically I had a "skin" like this:
SKIN.PHP:
<html>
<body>
<h1><?=$pageTitle?></h1>
<div id="content"><?=$pageContent?></div>
<div id="footer"><?=$pageFooter?></div>
</body>
</html>
Then i'd have a php file for each type of page. In my index.php I'd first include PAGE.PHP and then SKIN.PHP.
This of course mean PAGE.PHP looked something like this:
PAGE.PHP
<?
$pageTitle="Title of Page";
$pageContent=<<<ENDOFCONTENT
Lots of Content here.
ENDOFCONTENT;
$pageFooter="<hr>Footer of Page";
?>
Of course if the content part, which could be really long might include a lot of in and out of PHP it could get messy. also, I couldn't just place include($contentFileName) inside SKIN.PHP since the title and footer needed to be set before execution got there.
So what I really wanted was a page file like this:
BETTERPAGE.PHP
<?
$pageTitle="Title of Page";
$pageFooter="<hr>Footer of Page";
?>Normal in and out of PHP in the <?echo $body;?>
of the page
<?include("otherfile.php");
?>
and then have the output placed in $pageContent.
This function accomplished this:
function runPHP($phpFileName){
ob_start();
include($phpFileName);
$runPHPResult=ob_get_contents();
ob_end_clean();
return $runPHPResult;
}
so in my INDEX.PHP I could have something like:
<?
$pageContent=runPHP('betterpage.php');
require('skin.php');
?>
Hopw anybody else might find this usefull!
regards,
SN
since the title and footer needed to be set before execution got there.
SN