View Single Post
Old 11-30-2007, 07:59 PM   #2 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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
Tanax is offline  
Reply With Quote
The Following 2 Users Say Thank You to Tanax For This Useful Post:
iflashlord (05-03-2009), Nor (12-04-2007)