最新国产好看的视频,伊人天堂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)文章

最新評論

普兰店市| 凤冈县| 阿尔山市| 兰州市| 金门县| 佳木斯市| 寿宁县| 无棣县| 台北县| 杂多县| 日喀则市| 景东| 富锦市| 石嘴山市| 鄂温| 沾益县| 社旗县| 新巴尔虎左旗| 孟村| 息烽县| 民县| 贡觉县| 法库县| 绵竹市| 寿宁县| 保定市| 南京市| 宜黄县| 子长县| 台南县| 凌源市| 孟州市| 娄底市| 淅川县| 祁阳县| 石门县| 鄢陵县| 绩溪县| 宜黄县| 长乐市| 卢龙县|