PHP シンプルなカスタム テンプレート class_PHP チュートリアル

WBOY
リリース: 2016-07-13 17:46:23
オリジナル
1175 人が閲覧しました

    クラス MyTpl {
        プライベート $template_dir; 
        プライベート $compile_dir; 
        プライベート $tpl_vars=array(); 
 
        パブリック関数 __construct($template_dir="./templates", $compile_dir="./templates_c"){
            $this->template_dir=rtrim($template_dir,"/").'/'; 
            $this->compile_dir=rtrim($compile_dir, "/").'/'; 
        }
 
        パブリック関数 assign($tpl_var, $value=null){
            if($tpl_var!="")
                $this->tpl_vars[$tpl_var]=$value; 
        }
 
        public function display($fileName){
            $tplFile=$this->template_dir.$fileName; 
 
            if(!file_exists($tplFile)){
                false を返します。 
            }
 
            $comFileName=$this->compile_dir."com_".$fileName.".php"; 
 
            if(!file_exists($comFileName) || filemtime($comFileName) < filemtime($tplFile)){
                $repContent=$this->tpl_replace(file_get_contents($tplFile)); 
 
                file_put_contents($comFileName, $repContent);    
            }
 
            $comFileName を含めます。 
             
        }
 
        プライベート関数 tpl_replace($content){
                $pattern=array(
                        '/<{s*$([a-zA-Z_x7f-xff][a-zA-Z0-9_x7f-xff]*)s*}>/i'
                    ); 
 
                $replacement=array(
                    'tpl_vars["${1}"]; ?>' 
                    ); 
             
                $repContent=preg_replace($pattern, $replacement, $content); 
 
                $repContent を返します。 
        }
 
    }
?> 
抜粋:十分な_br的专栏

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/478594.html技術記事 ?php クラス MyTpl { プライベート $template_dir;プライベート $compile_dir;プライベート $tpl_vars=array(); public function __construct($template_dir=./templates, $compile_dir=./templates_c){ $this...
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!