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.
The following options are supported for Zend_Filter_Alpha:
A basic example of usage is below:
1 2 3 | $filter = new Zend_Filter_Alpha();
print $filter->filter('This is (my) content: 123');
|
The above example returns ‘Thisismycontent’. Notice that the whitespace characters and brackets are removed.
Note
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 Locale.
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:
1 2 3 | $filter = new Zend_Filter_Alpha(array('allowwhitespace' => true));
print $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.
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.