输出过滤器 {/programmers/plugins/plugins-outputfilters/}
输出过滤器插件在模板加载并执行后,但在输出显示之前,对模板的输出进行操作。
字符串
smarty_outputfilter_
名称
字符串
\$template_output
对象
\$template
输出过滤器函数的第一个参数是需要处理的模板输出,第二个参数是调用插件的 Smarty 实例。插件应该进行处理并返回结果。
<?php
/*
* Smarty 插件
* -------------------------------------------------------------
* 文件: outputfilter.protect_email.php
* 类型: outputfilter
* 名称: protect_email
* 目的: 将电子邮件地址中的 @ 符号转换为 %40,
* 作为对抗垃圾邮件机器人的简单保护
* -------------------------------------------------------------
*/
function smarty_outputfilter_protect_email($output, Smarty_Internal_Template $template)
{
return preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
'$1%40$2', $output);
}
?>