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_Alpha is a filter which returns the string $value, removing all but alphabetic characters. This filter includes an option to also allow white space characters.

Supported options for Zend_Filter_Alpha

The following options are supported for Zend_Filter_Alpha:

  • allowwhitespace: If this option is set then whitespace characters are allowed. Otherwise they are suppressed. By default whitespace characters are not allowed.

Basic usage

A basic example of usage is below:

= new Zend_Filter_Alpha();

$filter->filter('This is (my) content: 123');

The above example returns 'Thisismycontent'. Notice that the whitespace characters and brackets are removed.


Zend_Filter_Alpha works on most languages; however, there are three exceptions: Chinese, Japanese and Korean. With these languages the english alphabet is used. The language is detected through the use of Zend_Locale.

Allow whitespace characters

Zend_Filter_Alpha can also allow whitespace characters. This can be useful when you want to strip special characters from a string. See the following example:

= new Zend_Filter_Alpha(array('allowwhitespace' => true));

$filter->filter('This is (my) content: 123');

The above example returns 'This is my content '. Notice that the parenthesis, colon, and numbers have all been removed while the whitespace characters remain.

To change allowWhiteSpace after instantiation the method setAllowWhiteSpace() may be used.

To query the current value of allowWhiteSpace the method getAllowWhiteSpace() may be used.

Zend Framework