TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-26-2009, 09:48 PM   #1 (permalink)
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
Old 08-26-2009, 11:01 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Isn't eval() slow just like in JS?
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 08-26-2009, 11:28 PM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Eval is evil, avoid at all cost.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-27-2009, 06:36 AM   #4 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Quote:
Originally Posted by adamdecaf View Post
Isn't eval() slow just like in JS?
I don't know anything about JS.
Quote:
Originally Posted by Enfernikus View Post
Eval is evil, avoid at all cost.
Is there any other way to achieve the same result ??
hello-world is offline  
Reply With Quote
Old 08-27-2009, 07:49 PM   #5 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

File cached based on last modified time and output buffering
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-28-2009, 06:09 AM   #6 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

Why can't you just append those static HTML to a string? It seems to me like you're doing an excessive loop through a series of things...
TheOnly92 is offline  
Reply With Quote
Old 08-28-2009, 07:47 PM   #7 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Business logic and view logic should be strictly separated to facilitate easy ( relatively speaking ) future development and expansion.
__________________
My Blog
Enfernikus is offline  
Reply With Quote
The Following User Says Thank You to Enfernikus For This Useful Post:
hello-world (08-30-2009)
Old 08-30-2009, 11:08 AM   #8 (permalink)
The Contributor
 
hello-world's Avatar
 
Join Date: Feb 2009
Posts: 73
Thanks: 30
hello-world is on a distinguished road
Default

Quote:
Originally Posted by TheOnly92 View Post
Why can't you just append those static HTML to a string? It seems to me like you're doing an excessive loop through a series of things...
I though if do so.It would be slower using file_get_contents.

Quote:
Originally Posted by Enfernikus View Post
Business logic and view logic should be strictly separated to facilitate easy ( relatively speaking ) future development and expansion.
I agree with you , but I think I need more practice and your helps.

Thanks anyways.
hello-world is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template Phraser Scottymeuk Advanced PHP Programming 7 01-08-2009 09:07 PM
Template Class Issues WinSrev Advanced PHP Programming 20 11-04-2008 05:05 PM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
Template / Theme Parsing and Management TerrorRonin Advanced PHP Programming 6 03-18-2008 07:47 PM
Different style template system? Nor General 2 01-15-2008 01:10 PM


All times are GMT. The time now is 07:37 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design