最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

smarty高級特性之過濾器的使用方法

 更新時間:2015年12月25日 14:35:33   作者:釋然me  
這篇文章主要介紹了smarty高級特性之過濾器的使用方法,結(jié)合實例形式分析了smarty過濾器的相關(guān)使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例分析了smarty高級特性之過濾器的使用方法。分享給大家供大家參考,具體如下:

高級特性中過濾器的使用

1、預(yù)過濾器

function remove_dw_comments($tpl_source, &$smarty)
{
 return preg_replace("/<!--#.*-->/U","",$tpl_source);
 //去除原tpl文件中的注釋,使其在編譯后的文件中不顯示
}
//注冊預(yù)過濾器
$smarty->register_prefilter("remove_dw_comments");
$smarty->display("test1.tpl");

test1.tpl

<h1>與過濾器的使用</h1>
<!--#hello-->  注釋的格式
這樣的話,注釋在編譯后的文件中被過濾掉

2、后過濾器

function add_header_comment($tpl_source, &$smarty)
{
 return "<?php echo \"<!-- Created by Smarty! -->\n\" ?>\n".$tpl_source;
 //添加頭部注釋
}
//注冊后過濾器
$smarty->register_postfilter("add_header_comment");
$smarty->display('test2.tpl');

模板文件:

test2.tpl

頭部會產(chǎn)生注釋:

<!-- 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");

希望本文所述對大家基于smarty模板的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

西畴县| 松原市| 库伦旗| 枣阳市| 攀枝花市| 岱山县| 宝山区| 黑河市| 曲沃县| 怀安县| 临洮县| 个旧市| 华容县| 邵东县| 德保县| 安宁市| 巢湖市| 河北区| 个旧市| 黎川县| 高雄县| 民勤县| 剑河县| 汝城县| 邵武市| 府谷县| 全州县| 崇阳县| 吉木萨尔县| 巫溪县| 望都县| 黄梅县| 连南| 镇雄县| 龙江县| 固始县| 瓦房店市| 河池市| 北宁市| 武隆县| 玛多县|