输出过滤器

    输出过滤器插件作用于模板的输出,其时机在模板已调入并执行,但是还没有显示输出前。

string smarty_outputfilter_name (string $template_output, object &$smarty)

    输出过滤器插件函数的第一个参数是需要处理的模板输出,第二个参数是激活该插件的Smarty实例。插件应该进行处理并返回结果。

例子16-9. 输出过滤器插件

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     outputfilter.protect_email.php
 * Type:     outputfilter
 * Name:     protect_email
 * Purpose:  Converts @ sign in email addresses to %40 as
 *           a simple protection against spambots
 * -------------------------------------------------------------
 */
 
function smarty_outputfilter_protect_email($output, &$smarty)
 {
     return 
preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
                         
'$1%40$2'$output);
 }
?>

    参见register_outputfilter()unregister_outputfilter()