Home >Backend Development >PHP Tutorial >Filter usage example of zf framework_PHP tutorial

Filter usage example of zf framework_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:35:59865browse

Copy code The code is as follows:

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

require_once("Zend/Loader.php");
//Introducing Filter's string conversion to lowercase and uppercase classes
Zend_Loader::loadClass("Zend_Filter_StringToLower");
Zend_Loader:: loadClass("Zend_Filter_StringToUpper");
//Instantiate string to lowercase and uppercase classes
$Filter = new Zend_Filter_StringToLower();
$Filter2 = new Zend_Filter_StringToUpper();
// Set the string that needs to be converted
$Temp = 'ZHOUWUJIE  zhouwujie  ;
//Conversion method filter();
$Result = $Filter -> filter($Temp);
$ Result2 = $Filter2 -> filter($Temp);
echo $Result;
echo $Result2;
?>

Copy code The code is as follows:

/*How to use and operate the filter (filter chain)*/
require_once("Zend/Loader.php");
//The use of filter chain to load filters and filter method classes
Zend_Loader::loadClass("Zend_Filter ");
Zend_Loader::loadClass("Zend_Filter_Htmlentities");
Zend_Loader::loadClass("Zend_Filter_StripTags");
//Add the filter after instantiating the filter addFilter(new filter method class name ())
$Filter = new Zend_Filter();
$Filter //-> addFilter(new Zend_Filter_Htmlentities());
-> addFilter(new Zend_Filter_StripTags());
$ String = "Link";
$Result = $Filter -> filter($String);
echo $Result;
?> ;

Copy code 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','gambling','poison');
foreach ($List as $k => $v)
{
$value = str_replace($v , '*', $value);
}
return $value;
}
}
$Filter = new MyFilter();
$String = 'This message is Pornographic content';
$String2 = 'He went gambling today';
$String3 = 'He went to take drugs today';
echo "
Filter content
";
echo $Filter -> filter($String) . "
";
echo $Filter -> filter($String2) . "
";
echo $Filter - > filter($String3) . "
";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/741265.htmlTechArticleCopy the code as follows: ?php /*Simple usage and operation of the filter ()*/ require_once(" Zend/Loader.php"); //Introducing Filter's string conversion to lowercase and uppercase Zend_Loader::...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn