RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
RECOMMEND
SELECTED ENTRIES
RECENT COMMENTS
RECENT TRACKBACK
CATEGORIES
ARCHIVES
MOBILE
qrcode
LINKS
PROFILE
OTHERS

10
--
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
--
>>
<<
--

bose999's memo

<< PHPの主なエスケープシーケンス | main | OAuthを理解するためにtwitterで遊んでみた >>
PHPで簡単なテンプレートエンジン作ってみる
0
    PTTE.class.php(PHP Tiny Template Engine)
    <?php
    class PTTE{

        private function __construct(){}

        public static function
            makeString($templateFileName,$data = array()) {
            ob_start();
            extract($data);
            include $templateFileName;
            $str = ob_get_contents();
            ob_end_clean();
            return $str;
        }
    }


    sample.tmpl
    <html>
    <head><title><?=$title ?></title></head>
    <body>
    <ul>
    <?php foreach($bodies as $body): ?>
      <li><?=$body ?></li>
    <?php endforeach ?>
    </ul>
    </body>
    </html>


    do.php
    <?php
    require_once './PTTE.class.php';

    $bodies = array('test1','test2','test3');
    $data = array('title'=>'テンプレートのテスト','bodies'=>$bodies);

    print (PTTE::makeString('sample.tmpl',$data));
    | PHP | 14:37 | comments(0) | trackbacks(0) | - | - |









    http://bose.techie.jp/trackback/839143