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);
 }
     
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章