You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
I was not able to find an open or closed issue matching what I'm seeing.
This is not a question. (Questions should be asked on chat (Signup here) or our forums.)
A common use for these filters are names and addresses. They already have allow_white_spaces option, but it includes tabs and new lines. Can I create allow_printable_chars and allow_spaces options?
// Default settings, deny whitespace$filter = new \Zend\I18n\Filter\Alnum();
echo$filter->filter("This is (my) content: 123");
// Returns "Thisismycontent123"// First param in constructor is $allowWhiteSpace$filter = new \Zend\I18n\Filter\Alnum(true);
echo$filter->filter("This is (my)\t content:\n 123");
// Returns "This is my content// 123"// First param in constructor is also an array of options$filter = new \Zend\I18n\Filter\Alnum(['allow_printable_chars'=>true]);
echo$filter->filter("This is (my)\t content\n: 123");
// Returns "This is my content: 123"// First param in constructor is also an array of options$filter = new \Zend\I18n\Filter\Alnum(['allow_spaces'=>true]);
echo$filter->filter("This is (my)\t content\n: 123");
// Returns "This is my content 123"
The main change will be a new pattern /[[:^print:]]/ at filter().
publicfunctionfilter($value)
{
if (! is_scalar($value) && ! is_array($value)) {
return$value;
}
$whiteSpace = $this->options['allow_white_space'] ? '\s' : '';
$space = $this->options['allow_space'] ? '': $whiteSpace;
$printableChars = $this->options['allow_printable_chars'];
$language = Locale::getPrimaryLanguage($this->getLocale());
if (! static::hasPcreUnicodeSupport()) {
// POSIX named classes are not supported, use alternative [a-zA-Z] match$pattern = '/[^a-zA-Z' . $whiteSpace . ']/';
} elseif ($printableChars) {
$pattern = '/[[:^print:]]/u';
} elseif ($language === 'ja' || $language === 'ko' || $language === 'zh') {
// Use english alphabet$pattern = '/[^a-zA-Z' . $whiteSpace . ']/u';
} else {
// Use native language alphabet$pattern = '/[^\p{L}' . $whiteSpace . ']/u';
}
returnpreg_replace($pattern, '', $value);
}
1) tab new line
and spaces!@#
2)tab new line
and spaces
3)tabnewlineandspaces
4)tab new line
and spaces
5)tabnewlineandspaces
6)tabnew lineand spaces
7)tabnew lineand spaces
8)tabnew lineand spaces!@#
The text was updated successfully, but these errors were encountered:
Can I create allow_printable_chars and allow_spaces options?
Sure, help is always welcome! 😃
Would you be willing to provide a pull request? I would take over the extension of the documentation and the review of your pull request.
A common use for these filters are names and addresses. They already have
allow_white_spaces
option, but it includes tabs and new lines. Can I createallow_printable_chars
andallow_spaces
options?The main change will be a new pattern
/[[:^print:]]/
at filter().I don't know how asian chars behave with
:print:
Pattern tests
The text was updated successfully, but these errors were encountered: