[php-src] Issue #21428: Add FILTER_VALIDATE_STRLEN for UTF-8 string length validation
[email protected] (masakielastic)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/21428
Author: masakielastic
### Description
I would like to propose a new filter validator `FILTER_VALIDATE_STRLEN` that validates the length of a UTF-8 string.
The length is counted in Unicode code points. Grapheme clusters are not considered.
The validator supports `min_len` and `max_len` options and does not depend on the mbstring extension.
A prototype implementation is provided in the accompanying pull request.
```php
$options = [
'options' => [
'max_len' => 2,
'default' => 'error',
],
];
var_dump(
filter_var('🐘🐘🐘', FILTER_VALIDATE_STRLEN, $options)
);
```