Examples of using Filter filters in zf framework _ PHP Tutorial

Source: Internet
Author: User
Zf frame Filter use example. Copy the code as follows :? Php * Simple usage and operation of the Filter () * require_once (ZendLoader. php); introduction of the Filter string to lowercase class and to the uppercase class Zend_Loader :: The code is as follows:


/* Simple use and operation of the filter ()*/

Require_once ("Zend/Loader. php ");
// Convert the Filter string to lowercase or uppercase
Zend_Loader: loadClass ("Zend_Filter_StringToLower ");
Zend_Loader: loadClass ("Zend_Filter_StringToUpper ");
// Convert the instantiated string to lowercase or uppercase
$ Filter = new Zend_Filter_StringToLower ();
$ Filter2 = new Zend_Filter_StringToUpper ();
// Set the string to be converted
$ Temp = 'zhouwujie zhouwujie ';
// Conversion method filter ();
$ Result = $ Filter-> filter ($ Temp );
$ Result2 = $ Filter2-> filter ($ Temp );
Echo $ Result;
Echo $ Result2;
?>

The code is as follows:


/* Filter usage and operations (filter chain )*/
Require_once ("Zend/Loader. php ");
// Method class for loading filters and filters for the filter chain
Zend_Loader: loadClass ("Zend_Filter ");
Zend_Loader: loadClass ("Zend_Filter_Htmlentities ");
Zend_Loader: loadClass ("Zend_Filter_StripTags ");
// Add the filter addFilter (new filter method class name () after instantiating the filter ())
$ Filter = new Zend_Filter ();
$ Filter //-> addFilter (new Zend_Filter_Htmlentities ());
-> AddFilter (new Zend_Filter_StripTags ());
$ String = "link ";
$ Result = $ Filter-> filter ($ String );
Echo $ Result;
?>

The code is as follows:


/* Custom filter */
Require_once ("Zend/Loader. php ");
Zend_Loader: loadClass ("Zend_Filter_Interface ");
Class MyFilter implements Zend_Filter_Interface
{
Public function filter ($ value)
{
$ List = array ('Yellow ', 'Bet', 'poison ');
Foreach ($ List as $ k => $ v)
{
$ Value = str_replace ($ v, '*', $ value );
}
Return $ value;
}
}
$ Filter = new MyFilter ();
$ String = 'This message is yellow content ';
$ String2 = 'He has been gambling today ';
$ String3 = 'he is taking drugs today ';
Echo "filter content
";
Echo $ Filter-> filter ($ String )."
";
Echo $ Filter-> filter ($ String2 )."
";
Echo $ Filter-> filter ($ String3 )."
";
?>

The http://www.bkjia.com/PHPjc/741265.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/741265.htmlTechArticle code is as follows :? Php/* Simple usage and operations of filters () */require_once ("Zend/Loader. php "); // convert the string that introduces the Filter to lowercase and to Zend_Loader ::...

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.