<?php
class CBuffer {
function Start ($bFlag = true) {
ob_start();
}
function End () {
$this->content = ob_get_contents();
ob_end_clean();
$a1 = array();
$a2 = array();
foreach($this->to_transform as $k => $v) {
$a1[] = $k;
$a2[] = $v;
}
$this->content = str_replace($a1, $a2, $this->content);
return $this->content;
}
function SetParam ( $anchor, $value ) {
$this->to_transform[$this->hash($anchor)] = $value;
}
function ShowParam($anchor) {
return $this->hash($anchor);
}
private function hash ($s) {
return 'hash_'.md5($s);
}
public function Load($file) {
include $file;
}
}?>
<?php
$obj = new CBuffer;
$obj->Start();
$obj->Load('header.php');
$obj->Load('index.php');
$obj->Load('footer.php');
$obj->End();
?>
header.php:
<html>
<head>
<title><?=$this->ShowParam('title')?></title>
</head>
<body>
<?php
for($i=0;$i<100;$i++){
echo '<div>'.$i.'</div>';
}
?>
index.php
<?php
$this->SetParam('title', 'Заголовок');
for($i=0;$i<100;$i++){
echo '<div>'.$i.'</div>';
}
?>
footer.php
</body>
</html>
P.S. Работоспособность не проверял, под рукой сервера нет, так что синтактические ошибки могут присутствовать, но логика, думаю, понятна :)
P.P.S. Вопросы безопасности опущены