<< Back to man.ChinaUnix.net

Output Filters输出过滤器

Output filter plugins operate on a template's output, after the template is loaded and executed, but before the output is displayed.
输出过滤器插件的作用是,在装载并执行完一个模板之后显示模板之前,操作该模板的输出。

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

The first parameter to the output filter function is the template output that needs to be processed, and the second parameter is the instance of Smarty invoking the plugin. The plugin is supposed to do the processing and return the results.
输出过滤器函数第一个参数是需要处理的模板输出,第二个参数是调用这个插件的Smarty实例。此插件将会对参数进行处理并返回相应的结果。

Example 16-9. output filter plugin输出过滤器插件

/*
 * 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);
 }