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 的實例(instance)。此外掛在處理完後預設是會有回傳值的。
Example 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); } ?>
|
|