11-30-2007, 07:59 PM
|
#2 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
template.php
Located in /includes/classes/template.php
I'm not gonna go in-depth with this class, because there's already a tutorial for this class!
php Code:
class template { private $template_dir = 'includes/templates/'; private $file_ext = '.tpl'; private $buffer; public function load ($file) { if(file_exists($this-> template_dir . $file . $this-> file_ext)) { $this-> buffer = file_get_contents($this-> template_dir . $file . $this-> file_ext); return $this-> buffer; } else { echo $this-> template_dir . $file . $this-> file_ext . ' does not exist'; } } public function output ($input, $array) { $search = preg_match_all('/{.*?}/', $input, $matches); for($i = 0; $i < $search; $i++ ) { $matches[ 0][ $i] = str_replace(array('{', '}'), null, $matches[ 0][ $i] ); } foreach($matches[ 0] as $value) { $input = str_replace('{' . $value . '}', $array[ $value], $input); } echo $input; } }
Link to tutorial: Pixel2life
|
|
|
|