/', $template[$i]) ) { // ok, we found a begin block... let's skip it for now. while($tmp = preg_match('//', $template[$i])) { if ($tmp == TRUE) { // we succeeded in finding the end, stop. break; } if($i = count($template) ) { // oops, no end block, let's break out of this. break; } $i++; } } $keys = array_keys($vars); for($j=0; $j/', $template[$i]) ) { // ok, found the block we're looking for... let's find and replace the variables $begin = $i+1; } if( preg_match('//', $template[$i]) ) { // we're at the end, break. $end = $i-1; } } for($i=$begin; $i<($end+1); $i++) { for($j=0; $j and // Not useful, not terrible, I say trash it. // $template[$begin-1] = ''; $template[$end+1] = ''; return $template; } function show_page($template) { // ok, all our work has done, let's just spit it out. for($i=0; $i < count($template); $i++) { echo $template[$i]; } } $tpl = load_template('default', 'header.tpl'); $tpl = parse_template($tpl, array('LOGIN' => 'login.php', 'LOGGED_IN' => 'Log in')); $tpl = parse_block($tpl, 'test', array(array('TEST' => 'testing'), array('TEST' => 'testing'))); show_page($tpl);