亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

smarty高級(jí)特性之過(guò)濾器的使用方法

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

本文實(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ì)有所幫助。

相關(guān)文章

最新評(píng)論