1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<!--?php
    class Template {
         
        public $filename;
      public $assigned_vars=array();
         
        public function set($key, $value) {
        $this--->assigned_vars[$key] = $value;
      }
       
        public function display() {
          if(file_exists($this->filename)) {
            $output = file_get_contents($this->filename);
            foreach($this->assigned_vars as $key => $value) {
              $output = preg_replace('/{'.$key.'}/', $value, $output);
            }
            echo $output;
          } else {
            echo "*** Missing template error ***";
          }
        }
    }
     
    $template = new Template();
    $template->filename = "template2.php";
    $template->set('page_title', "Template Test");
    $template->set('content', "This is a test of templating using search and replace.");
    $template->display();
 
?>
 
// template2.php
 
     
      <title>{page_title}</title>
     
     
     
        <h1>{page_title}</h1>
 
        <p>{content}</p>
         
    


Template Test

This is a test of templating using search and replace.

'개발관련 > PHP' 카테고리의 다른 글

[PHP]Upload  (0) 2012.04.20
[PHP]Template Variable  (0) 2012.04.20
[PHP]Template Replace  (0) 2012.04.20
[PHP]Static Modifier  (0) 2012.04.20
[PHP]Server Variables  (0) 2012.04.20
Posted by 파노카페
: