smarty高级特性之过滤器的使用方法
2015-12-25 00:00
423 查看
本文实例分析了smarty高级特性之过滤器的使用方法。分享给大家供大家参考,具体如下:
高级特性中过滤器的使用
1、预过滤器
test1.tpl
<h1>与过滤器的使用</h1>
<!--#hello--> 注释的格式
这样的话,注释在编译后的文件中被过滤掉
2、后过滤器
模板文件:
test2.tpl
头部会产生注释:
<!-- Created by Smarty! -->
3、输出滤镜
希望本文所述对大家基于smarty模板的PHP程序设计有所帮助。
Smarty变量调节器失效的解决办法
FCKeditor smarty 编辑器的应用PHP
smarty中常用方法实例总结
Thinkphp+smarty+uploadify实现无刷新上传
CodeIgniter中使用Smarty3基本配置
高级特性中过滤器的使用
1、预过滤器
function remove_dw_comments($tpl_source, &$smarty) { return preg_replace("/<!--#.*-->/U","",$tpl_source); //去除原tpl文件中的注释,使其在编译后的文件中不显示 } //注册预过滤器 $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
头部会产生注释:
<!-- 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程序设计有所帮助。
您可能感兴趣的文章:
smarty中先strip_tags过滤html标签后truncate截取文章运用Smarty变量调节器失效的解决办法
FCKeditor smarty 编辑器的应用PHP
smarty中常用方法实例总结
Thinkphp+smarty+uploadify实现无刷新上传
CodeIgniter中使用Smarty3基本配置
相关文章推荐
- 详解WordPress开发中过滤属性以及Sql语句的函数使用
- smarty高级特性之对象的使用方法
- 详解WordPress中提醒安装插件以及隐藏插件的功能实现
- WordPress中创建用户角色的相关PHP函数使用详解
- PHP版本升级到7.x后wordpress的一些修改及wordpress技巧
- PHP获取二维数组中某一列的值集合
- SqlServer使用 case when 解决多条件模糊查询问题
- js实现简单的验证码
- js实现文本框输入文字个数限制代码
- 基于jquery实现省市区三级联动效果
- 理解JavaScript中worker事件api
- 理解javascript中DOM事件
- 学习JavaScript鼠标响应事件
- javascript实现简单加载随机色方块
- 理解javascript中try...catch...finally
- jquery.cookie.js用法实例详解
- js实现跨域的多种方法
- js操作cookie保存浏览记录的方法
- jQuery实现模仿微博下拉滚动条加载数据效果
- 使用堆实现Top K算法(JS实现)