This article mainly introduces examples of using the Filter in the zf framework. The Code contains comments. For more information, see
This article mainly introduces examples of using the Filter in the zf framework. The Code contains comments. For more information, see
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 )."
";
?>
,