<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_21853"> 简易的smarty 对新手理解smarty有帮助 源于itcast韩顺平老师smarty第2、3讲 <div class="blockcode"> <div id="code_i3O"><ol> <li><?php<li><li> class MyMiniSmarty{<li> <li> public $template_dir = "./templates";<li> public $complie_dir = "./templates_c";<li> public $tpl_vars = array();<li> <li> public function assign($tpl_var,$val = NULL){<li> if(!empty($tpl_var)){<li> $this->tpl_vars[$tpl_var] = $val;</li> <li> }</li> <li> }</li> <li> </li> <li> public function display($tpl_file){</li> <li> $tpl_file_path = $this->template_dir.$tpl_file;</li> <li> $complie_file_path = $this->complie_dir."com_".$tpl_file.".php";</li> <li> if (file_exists($tpl_file_path) || filemtime($tpl_file_path) < filemtime($complie_file_path)) {<li> $tpl_file_content = file_get_contents($tpl_file_path);<li> <li> $pattern = array(<li> '/{s*$([a-zA-Z0-0_]*)s*}/i'<li> );<li> <li> $replace = array(<li> '<?php echo $this->tpl_vars["$程序猿闯子"] ?>'</li> <li> );</li> <li> </li> <li> $new_content = preg_replace($pattern, $replace, $tpl_file_content);</li> <li> </li> <li> try {</li> <li> file_put_contents($complie_file_path, $new_content);</li> <li> } catch (Exception $e) {</li> <li> echo $e->getMessage();</li> <li> }</li> <li> include $complie_file_path;</li> <li> </li> <li> }else {</li> <li> return FALSE;</li> <li> } </li> <li> }</li> <li> </li> <li> }</li> <li>?></li> </ol></div> <em onclick="copycode($('code_i3O'));">复制代码</em> </div> </td></tr></table> <div id="comment_21853" class="cm"> </div> <div id="post_rate_div_21853"></div> <br><br>