smarty高級(jí)特性之過(guò)濾器的使用方法
本文實(shí)例分析了smarty高級(jí)特性之過(guò)濾器的使用方法。分享給大家供大家參考,具體如下:
高級(jí)特性中過(guò)濾器的使用
1、預(yù)過(guò)濾器
function remove_dw_comments($tpl_source, &$smarty) { return preg_replace("/<!--#.*-->/U","",$tpl_source); //去除原tpl文件中的注釋?zhuān)蛊湓诰幾g后的文件中不顯示 } //注冊(cè)預(yù)過(guò)濾器 $smarty->register_prefilter("remove_dw_comments"); $smarty->display("test1.tpl");
test1.tpl
<h1>與過(guò)濾器的使用</h1>
<!--#hello--> 注釋的格式
這樣的話(huà),注釋在編譯后的文件中被過(guò)濾掉
2、后過(guò)濾器
function add_header_comment($tpl_source, &$smarty) { return "<?php echo \"<!-- Created by Smarty! -->\n\" ?>\n".$tpl_source; //添加頭部注釋 } //注冊(cè)后過(guò)濾器 $smarty->register_postfilter("add_header_comment"); $smarty->display('test2.tpl');
模板文件:
test2.tpl
頭部會(huì)產(chǎn)生注釋?zhuān)?/p>
<!-- Created by Smarty! -->
3、輸出濾鏡
function protect_email($tpl_output, &$smarty){ $tpl_output = preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!', '$1%40$2', $tpl_output); return $tpl_output;}// register the outputfilter$smarty->register_outputfilter("protect_email"); $smarty->display("index.tpl"); } $smarty->register_outputfilter("protect_email"); $smarty->display("index.tpl");
希望本文所述對(duì)大家基于smarty模板的PHP程序設(shè)計(jì)有所幫助。
- Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)
- Zend Framework實(shí)現(xiàn)Zend_View集成Smarty模板系統(tǒng)的方法
- Codeigniter中集成smarty和adodb的方法
- PHP文件緩存smarty模板應(yīng)用實(shí)例分析
- yii,CI,yaf框架+smarty模板使用方法
- smarty高級(jí)特性之對(duì)象的使用方法
- php實(shí)現(xiàn)smarty模板無(wú)限極分類(lèi)的方法
- smarty簡(jiǎn)單應(yīng)用實(shí)例
- Smarty使用自定義資源的方法
- smarty中常用方法實(shí)例總結(jié)
- Smarty最簡(jiǎn)單實(shí)現(xiàn)列表奇偶變色的方法
- Smarty foreach控制循環(huán)次數(shù)的一些方法
- CodeIgniter中使用Smarty3基本配置
- smarty學(xué)習(xí)筆記之常見(jiàn)代碼段用法總結(jié)
相關(guān)文章
ThinkPHP連接數(shù)據(jù)庫(kù)及主從數(shù)據(jù)庫(kù)的設(shè)置教程
這篇文章主要介紹了ThinkPHP連接數(shù)據(jù)庫(kù)及主從數(shù)據(jù)庫(kù)的設(shè)置方法,是進(jìn)行大型web項(xiàng)目開(kāi)發(fā)十分有用的技巧,需要的朋友可以參考下2014-08-08Laravel 實(shí)現(xiàn)添加多語(yǔ)言提示信息
今天小編就為大家分享一篇Laravel 實(shí)現(xiàn)添加多語(yǔ)言提示信息,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10ThinkPHP控制器間實(shí)現(xiàn)相互調(diào)用的方法
這篇文章主要介紹了ThinkPHP控制器間實(shí)現(xiàn)相互調(diào)用的方法,主要通過(guò)A()方法實(shí)現(xiàn)這一功能,可以有效的提高代碼的重復(fù)利用率,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-10-10PHP使用Face++接口開(kāi)發(fā)微信公眾平臺(tái)人臉識(shí)別系統(tǒng)的方法
這篇文章主要介紹了PHP使用Face++接口開(kāi)發(fā)微信公眾平臺(tái)人臉識(shí)別系統(tǒng)的方法,涉及微信公眾平臺(tái)相關(guān)接口的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04php通過(guò)PHPExcel導(dǎo)入Excel表格到MySQL數(shù)據(jù)庫(kù)的簡(jiǎn)單實(shí)例
下面小編就為大家?guī)?lái)一篇php通過(guò)PHPExcel導(dǎo)入Excel表格到MySQL數(shù)據(jù)庫(kù)的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10PHP使用array_multisort對(duì)多個(gè)數(shù)組或多維數(shù)組進(jìn)行排序
這篇文章主要介紹了PHP使用array_multisort對(duì)多個(gè)數(shù)組或多維數(shù)組進(jìn)行排序,需要的朋友可以參考下2014-12-12TP5.0框架實(shí)現(xiàn)無(wú)限極回復(fù)功能的方法分析
這篇文章主要介紹了TP5.0框架實(shí)現(xiàn)無(wú)限極回復(fù)功能的方法,結(jié)合實(shí)例形式分析了thinkPHP5.0框架下無(wú)限極回復(fù)功能相關(guān)的數(shù)據(jù)庫(kù)、評(píng)論功能及界面布局實(shí)現(xiàn)方法,需要的朋友可以參考下2019-05-05