Studyon Minte9.com
ZF 1.0

Study

Types



# Alnum
	$filter = new Zend_Filter_Alnum();
	$return = $filter->filter('This is (my) content: 123'); // return Thisismycontent123

# Alpha
	$filter = new Zend_Filter_Alpha(array('allowwhitespace'=>true));
	$return = $filter->filter('This is (my) content: 123'); // return This is mycontent

# BaseName
	$filter = new Zend_Filter_BaseName();
	$return = $filter->filter('/vol/tmp/filename.txt'); // return filename.txt

# Compress
	// string
	$filter = new Zend_Filter_Compress();
	$return = $filter->filter('Uncompressed string');
	$filter = new Zend_Filter_Decompress();
	$return = $filter->filter($return);
	// file
	$filter = new Zend_Filter_Compress(array(
		'adapter' => 'zip',
		'options' => array(
			'archive' => 'index.zip'
		)
	));
	$result = $filter->filter('C:htdocszfsitehtmlindex.php');

		// Error: This filter needs the zip extension
		// Solution: add php zip extension

		// Rar Error: No compression callback available
		// Reason: Due to restrictions with the Rar compression format, there is no compression available for free

		// http://www.thomasweidner.com/flatpress/2009/09/20/compression-and-decompression-for-zf/


# Digits
	$filter = new Zend_Filter_Digits();
	$return = $filter->filter('October 2009'); // return 2009

# Dir
	$filter = new Zend_Filter_Dir();
	$return = $filter->filter('/etc/passwd'); // return /etc

# Encrypt & Decrypt
	// Actually there are adapters for the Mcrypt and OpenSSL extensions from PHP
	// When you do not supply the adapter option the Mcrypt adapter will be used per default. 

	$filter = new Zend_Filter_Encrypt(array('key'=>'myencryptionkey'));
	$filter->setVector('aaaaaaaa'); // 8 chars
	$return = $filter->filter('text_to_be_encoded'); 

	$filter = new Zend_Filter_Decrypt(array('key'=>'myencryptionkey'));
	$filter->setVector('aaaaaaaa');
	$return = $filter->filter($return);
	$return = trim($return);

		// Error: This filter needs the mcrypt extension 
		// Solution: add php mcrypt extension

		// http://www.codediesel.com/php/encrypting-uploaded-files-in-php/


# HtmlEntities
	$filter = new Zend_Filter_HtmlEntities();
	$return = $filter->filter('<'); // return &lt;
	$return = $filter->filter('&'); // return &amp;

# PregReplace
	$filter = new Zend_Filter_PregReplace(array(
		'match' => '/bob/',
		'replace' => 'john',
	));
	$return = $filter->filter("Hi bob!"); // return Hi john!

# StripTags
	$filter = new Zend_Filter_StripTags(array('allowTags' => 'a'));
	$return = $filter->filter("A text with <br/> a <a href='link.com'>link</a>"); // return  "A text with  a <a>link</a>"


http://framework.zend.com/manual/en/zend.filter.set.html