<?php
$page = $_GET['p'] ? $page = $_GET['p'] : $page = "main";
include "./ps/loadtpl.php";
getTemplate($page);
?>
loadtpl.php
(предупреждение! тут изрядно накурено!:3)
<?php
function loadTemplate($name) {
(String) $name = file_exists('./tpl/' . $name . '.tpl') ? $name = './tpl/' . $name . '.tpl' : $name = "./tpl/blank.tpl";
$file = fopen($name, "r");
(String) $content = fread($file, filesize($name));
preg_match(str_replace('*','([А-Яа-яЁёa-zA-Z]+)','|{*}|u'), $content, $out);
while ($out[0] != null) {
$content = str_replace($out[0], loadTemplate(substr($out[0], 1, (strlen($out[0]) - 2))), $content);
preg_match('|{([А-Яа-яЁёa-zA-Z]+)}|u', $content, $out);
}
return $content;
fclose($file);
}
function getTemplate($name) {
echo loadTemplate($name);
}
?>