Filters
In This Article
Alnum
The Alnum
filter can be used to return only alphabetic characters and
digits in the unicode "letter" and "number" categories, respectively. All
other characters are suppressed.
Basic Usage
$filter = new Zend\I18n\Filter\Alnum();
echo $filter->filter("This is (my) content: 123"); // "Thisismycontent123"
By default, if no locale is provided, Alnum
will use the system locale
provide by PHP's Locale
class and the getDefault()
method.
Using Whitespace
To allow whitespace characters (\s
) on filtering set the option to true
;
otherwise they are suppressed.
$filter = new Zend\I18n\Filter\Alnum(true);
echo $filter->filter("This is (my) content: 123"); // "This is my content 123"
$filter = new Zend\I18n\Filter\Alnum();
$filter->setAllowWhiteSpace(true);
echo $filter->filter("This is (my) content: 123"); // "This is my content 123"
Get Current Value
To get the current value of this option, use the getAllowWhiteSpace()
method.
$filter = new Zend\I18n\Filter\Alnum(true);
var_dump($filter->getAllowWhiteSpace()); // true
Default Value
The default value of this option is false
that means whitespace characters are
suppressed.
Using Locale
The locale string used in identifying the characters to filter (locale name,
e.g. en_US
).
$filter = new Zend\I18n\Filter\Alnum(null, 'en_US');
echo $filter->filter("This is (my) content: 123"); // "Thisismycontent123"
$filter = new Zend\I18n\Filter\Alnum();
$filter->setLocale('en_US');
echo $filter->filter("This is (my) content: 123"); // "Thisismycontent123"
Locale::setDefault('en_US');
$filter = new Zend\I18n\Filter\Alnum();
echo $filter->filter("This is (my) content: 123"); // "Thisismycontent123"
Get Current Value
To get the current value of this option, use the getLocale()
method.
$filter = new Zend\I18n\Filter\Alnum(null, 'en_US');
echo $filter->getLocale(); // 'en_US'
Default Value
By default, if no locale is provided, Alnum
will use the system locale
provide by PHP's Locale::getDefault()
.
Supported Languages
Alnum
works for most languages, except Chinese, Japanese and Korean. Within
these languages, the English alphabet is used instead of the characters from
these languages. The language itself is detected using the Locale
class.
Found a mistake or want to contribute to the documentation? Edit this page on GitHub!