Alnum

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.

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.

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:

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().

Project Versions

Table Of Contents

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

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.

  1. Login with your GitHub account.
  2. Go to Alnum on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.