View Single Post
Old 08-26-2009, 09:48 PM   #1 (permalink)
hello-world
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default Template How ? ?

After a long period of time I understand how to separate php from html.The book php in Action has lots of details about.
But now there is one problem that it is slower than I thought.
Here I have include this file.Can you please tell me why is that so ?

PHP Code:
Class Template {
    public 
$data;
    public 
$file;
    
    public function 
__construct($file,$var,$value){
         
$this->file file_get_contents($file);
         
$this->data[$var] = $value;
         
    }
    
    public function 
set(){
        
//Search for any thing side {} and Save the result in matches(array)
        
preg_match_all("/{.*?}/",$this->file,$matches);
        
        
//loop through the result of matches
        
foreach($matches as $skey => $value){
            
//loop through data
            
foreach($this->data as $val ){
            
            if(
in_array($val,$value)){
                
                foreach(
$this->data as $myKey =>$valo)
                
                
$string =str_replace($val,$myKey,$this->file);
                
                 eval(
"?>".$string);
                
                } else {
                    echo 
"not found";
                    echo eval(
"?>".$this->file);
                    
                     break; 
                }
            }
        }
    }
    
    public function 
parser(){
        
ob_start();
        
$this->set();
        
$string ob_get_contents();
        
ob_get_clean();
        return  
$string;
    }

hello-world is offline  
Reply With Quote