All pastes #552312 Raw Edit

Syosoft

public php v1 · immutable
·published 2007-06-09 07:01 UTC
rendered paste body
<!-- BEGIN TEMPLATE FILE: tpl.main.php --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">	<head>		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />		<title>%title%</title>		<meta name="description" content="%description%" />		<meta name="keywords" content="%keywords%" />	</head>	<body>		%content%	</body></html><!-- END TEMPLATE FILE: tpl.main.php --><!-- BEGIN CONTENT FILE: home.php --><?php	set_tpl_var('title','Home Page');	set_tpl_var('description','This is our home page.');	set_tpl_var('keywords','These are key words');?><h1>Home Page</h1><p>This is the home page.</p><!-- END TEMPLATE FILE: home.php --><!-- BEGIN CONTROL FILE: index.php --><?php	$template_variables = array();	function set_tpl_var($name,val) { 		global $template_variables;		$template_variables[$name] = $val;	}	// Load content file first so tpl vars get set	ob_start();	include 'home.php';	$content = ob_get_clean();	// Load template file	ob_start();	include 'tpl.main.php';	$template = ob_get_clean();	// Merge content into template	$output = str_replace('%content%',$content,$template);	// Find and replace all template variables	if(preg_match_all('/%(.*?)%',$output,$tpl_vars)) : 		foreach($tpl_vars[1] as $tpl_var) : 			$find 		= '%'.$tpl_var.'%';			$replace	= isset($template_variables[$tpl_var]) ? $template_variables[$tpl_var] : '';			$output		= str_replace($find,$replace,$output);		endforeach;	endif;	// Output page	echo $output;?><!-- END CONTROL FILE: index.php -->