How to use the smarty advanced features filter, _ PHP Tutorial

Source: Internet
Author: User
Smarty advanced features: how to use filters ,. The usage of smarty advanced features filters is analyzed in this article. For your reference, refer to the usage of the smarty advanced filter in advanced features,

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.

Articles you may be interested in:
  • In smarty, use strip_tags to filter html tags and truncate to capture articles
  • Solution to Smarty variable regulator failure
  • FCKeditor smarty editor application PHP
  • Summary of examples of common methods in smarty
  • Thinkphp + smarty + uploadify
  • Use the basic configuration of Smarty3 in CodeIgniter

The usage of the smarty advanced feature filter is analyzed in this article. I will share it with you for your reference as follows: Advanced features...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.