Zend_Filter_Alnum is a filter which returns only alphabetic characters and digits. All other characters are supressed.
The following options are supported for Zend_Filter_Alnum:
See the following example for the default behaviour of this filter.
1 2 3 | $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.
Note
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 Locale.
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:
1 2 3 | $filter = 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().
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.