Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


Zend_Filter_Alnum is a filter which returns only alphabetic characters and digits. All other characters are supressed.

Supported options for Zend_Filter_Alnum

The following options are supported for Zend_Filter_Alnum:

  • allowwhitespace: If this option is set then whitespace characters are allowed. Otherwise they are supressed. Per default whitespaces are not allowed.

Basic usage

See the following example for the default behaviour of this filter.

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

The above example returns 'Thisismycontent123'. As you see all whitespaces and also the brackets are filtered.


Zend_Filter_Alnum works on almost all languages. But actually there are three exceptions: Chinese, Japanese and Korean. Within these languages the english alphabet is use instead of the characters from these languages. The language itself is detected by using Zend_Locale.

Allow whitespaces

Zend_Filter_Alnum can also allow whitespaces. This can be usefull when you want to strip special chars from a text. See the following example:

= new Zend_Filter_Alnum(array('allowwhitespace' => true));
$return $filter->filter('This is (my) content: 123');
// returns 'This is my content 123'

The above example returns 'This is my content 123'. As you see only the brackets are filtered whereas the whitespaces are not touched.

To change allowWhiteSpace afterwards you can use setAllowWhiteSpace() and getAllowWhiteSpace().

Zend Framework