: This article describes how to use the filter of smarty's advanced features. if you are interested in the PHP Tutorial, refer to it. This document describes how to use the smarty advanced filter. We will share this with you for your reference. The details are as follows:
Use of filters in Advanced features
1. pre-filter
Function remove_dw_comments ($ tpl_source, & $ smarty) {return preg_replace ("/
/U "," ", $ tpl_source); // remove comments from the original tpl file, make it not displayed in the compiled file} // register the pre-filter $ smarty-> register_prefilter ("remove_dw_comments"); $ smarty-> display ("test1.tpl ");
Test1.tpl
Use of filters
Annotation format
In this case, the comment is filtered out in the compiled file.
2. post filter
Function add_header_comment ($ tpl_source, & $ smarty) {return "<? Php echo \"
\ N \ "?> \ N ". $ tpl_source; // add header annotation} // after registration filter $ smarty-> register_postfilter ("add_header_comment"); $ smarty-> display ('test2. tpl ');
Template File:
Test2.tpl
Comments are generated in the header:
3. output filter
function protect_email($tpl_output, &$smarty){ $tpl_output = preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!', '$1%40$2', $tpl_output); return $tpl_output;}// register the outputfilter$smarty->register_outputfilter("protect_email"); $smarty->display("index.tpl");}$smarty->register_outputfilter("protect_email");$smarty->display("index.tpl");
I hope this article will help you design PHP programs based on the smarty template.
The above describes how to use the smarty advanced features filter, including the content, hope to be helpful to friends who are interested in PHP tutorials.