3 zend-i18n ships with a set of internationalization-related filters.
7 The `Alnum` filter can be used to return only alphabetic characters and digits in the unicode
8 "letter" and "number" categories, respectively. All other characters are suppressed.
12 The following options are supported for `Alnum`:
15 Alnum([ boolean $allowWhiteSpace [, string $locale ]])
18 - `$allowWhiteSpace`: If set to true, whitespace characters are allowed;
19 otherwise they are suppressed. Default is `false` (whitespace is not allowed).
20 Methods for getting/setting the allowWhiteSpace option are also available
21 (`getAllowWhiteSpace()` and `setAllowWhiteSpace()`).
22 - `$locale`: The locale string used in identifying the characters to filter
23 (locale name, e.g. `en_US`). If unset, it will use the default locale
24 (`Locale::getDefault()`). Methods for getting/setting the locale are also
25 available (`getLocale()` and `setLocale()`).
30 // Default settings, deny whitespace
31 $filter = new \Zend\I18n\Filter\Alnum();
32 echo $filter->filter("This is (my) content: 123");
33 // Returns "Thisismycontent123"
35 // First param in constructor is $allowWhiteSpace
36 $filter = new \Zend\I18n\Filter\Alnum(true);
37 echo $filter->filter("This is (my) content: 123");
38 // Returns "This is my content 123"
41 > ### Supported languages
43 > `Alnum` works for most languages, except Chinese, Japanese and Korean. Within
44 > these languages, the English alphabet is used instead of the characters from
45 > these languages. The language itself is detected using the `Locale` class.
49 The `Alpha` filter can be used to return only alphabetic characters in the unicode "letter"
50 category. All other characters are suppressed.
54 The following options are supported for `Alpha`:
57 Alpha([ boolean $allowWhiteSpace [, string $locale ]])
60 - `$allowWhiteSpace`: If set to true, whitespace characters are allowed;
61 otherwise they are suppressed. Default is `false` (whitespace is not allowed).
62 Methods for getting/setting the allowWhiteSpace option are also available
63 (`getAllowWhiteSpace()` and `setAllowWhiteSpace()`).
64 - `$locale`: The locale string used in identifying the characters to filter
65 (locale name, e.g. `en_US`). If unset, it will use the default locale
66 (`Locale::getDefault()`). Methods for getting/setting the locale are also
67 available (`getLocale()` and `setLocale()`).
72 // Default settings, deny whitespace
73 $filter = new \Zend\I18n\Filter\Alpha();
74 echo $filter->filter("This is (my) content: 123");
75 // Returns "Thisismycontent"
78 $filter = new \Zend\I18n\Filter\Alpha(true);
79 echo $filter->filter("This is (my) content: 123");
80 // Returns "This is my content "
84 > ### Supported languages
86 > `Alnum` works for most languages, except Chinese, Japanese and Korean. Within
87 > these languages, the English alphabet is used instead of the characters from
88 > these languages. The language itself is detected using the `Locale` class.
92 The `NumberFormat` filter can be used to return locale-specific number and
93 percentage strings. It extends the `NumberParse` filter, which acts as wrapper
94 for the `NumberFormatter` class within ext/intl.
98 The following options are supported for `NumberFormat`:
101 NumberFormat([ string $locale [, int $style [, int $type ]]])
104 - `$locale`: The locale string used in identifying the characters to filter
105 (locale name, e.g. `en_US`). If unset, it will use the default locale
106 (`Locale::getDefault()`). Methods for getting/setting the locale are also
107 available (`getLocale()` and `setLocale()`).
108 - `$style`: (Optional) Style of the formatting, one of the [`NumberFormatter`
109 format style constants](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle).
110 If unset, it will use `NumberFormatter::DEFAULT_STYLE` as the default style.
111 Methods for getting/setting the format style are also available (`getStyle()`
113 - `$type`: (Optional) The [`NumberFormatter` formatting type](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.types)
114 to use. If unset, it will use `NumberFormatter::TYPE_DOUBLE` as the default
115 type. Methods for getting/setting the format type are also available
116 (`getType()` and `setType()`).
121 $filter = new \Zend\I18n\Filter\NumberFormat('de_DE');
122 echo $filter->filter(1234567.8912346);
123 // Returns "1.234.567,891"
125 $filter = new \Zend\I18n\Filter\NumberFormat('en_US', NumberFormatter::PERCENT);
126 echo $filter->filter(0.80);
129 $filter = new \Zend\I18n\Filter\NumberFormat('fr_FR', NumberFormatter::SCIENTIFIC);
130 echo $filter->filter(0.00123456789);
131 // Returns "1,23456789E-3"
136 The `NumberParse` filter can be used to parse a number from a string. It acts as
137 a wrapper for the `NumberFormatter` class within ext/intl.
139 ### Supported Options
141 The following options are supported for `NumberParse`:
144 NumberParse([ string $locale [, int $style [, int $type ]]])
147 - `$locale`: The locale string used in identifying the characters to filter
148 (locale name, e.g. `en_US`). If unset, it will use the default locale
149 (`Locale::getDefault()`). Methods for getting/setting the locale are also
150 available (`getLocale()` and `setLocale()`).
151 - `$style`: (Optional) Style of the parsing, one of the [`NumberFormatter` format style constants](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle).
152 If unset, it will use `NumberFormatter::DEFAULT_STYLE` as the default style.
153 Methods for getting/setting the parse style are also available (`getStyle()`
155 - `$type`: (Optional) The [`NumberFormatter` parsing type](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.types)
156 to use. If unset, it will use `NumberFormatter::TYPE_DOUBLE` as the default
157 type. Methods for getting/setting the parse type are also available
158 (`getType()` and `setType()`).
163 $filter = new \Zend\I18n\Filter\NumberParse('de_DE');
164 echo $filter->filter('1.234.567,891');
165 // Returns 1234567.8912346
167 $filter = new \Zend\I18n\Filter\NumberParse('en_US', NumberFormatter::PERCENT);
168 echo $filter->filter('80%');
171 $filter = new \Zend\I18n\Filter\NumberParse('fr_FR', NumberFormatter::SCIENTIFIC);
172 echo $filter->filter('1,23456789E-3');
173 // Returns 0.00123456789