Zend Framework implements the custom filter method, zendframework

Source: Internet
Author: User

Zend Framework implements the custom filter method, zendframework

This example describes how to implement a custom filter using Zend Framework. We will share this with you for your reference. The details are as follows:

Create a custom filter

Code:

<? Phprequire_once 'zend/Filter/Interface. php '; class MyFilter implements Zend_Filter_Interface {public function filter ($ value) {$ badlist = array ("Pear", "strawberry", "apple "); for ($ I = 0; $ I <count ($ badlist); $ I ++) {$ value = str_replace ($ badlist [$ I], "*", $ value) ;}return $ value ;}$ filter = new MyFilter (); $ temp1 = "Delicious oranges"; $ temp2 = "I like Apple "; $ temp3 = "nice pear, but my favorite dish is Strawberry! "; Echo" content :". $ temp1. "<p> after filtering:"; echo $ filter-> filter ($ temp1); echo "<p>"; echo "content :". $ temp2. "<p> after filtering:"; echo $ filter-> filter ($ temp2); echo "<p>"; echo "content :". $ temp3. "<p> after filtering:"; echo $ filter-> filter ($ temp3); echo "<p> ";

Result:

Content: oranges are delicious.

After filtering, the results show that the oranges are delicious.

Content: I like apple

After filtering: I like to eat *

Content: pear is also good, but my favorite food is Strawberry!

After filtering, it will be: * which is good, but what I like most is *!

Analysis:

The filter method is implemented after the interface is inherited. Then instantiate this class and call this method. You can complete the content you want to filter.

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.