[php-src] Issue #20984: Expose a function to check whether a string is valid UTF-8
[email protected] (stof)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Issue: https://github.com/php/php-src/issues/20984 Author: stof ### Description Checking whether a string is valid UTF-8 is a common need, as many projects require UTF-8 encoding (to be able to use the `u` modifier in regex for instance, among other use cases). As `zend_string` already has internal optimizations to remember that a string is valid UTF-8, implementing such function in core would provide several benefits over a userland implementation (it can both read the flag for a fast-path answer and set the flag at the end of the slow path to remember the validity for next usages of the string). This could be implemented as a function `is_valid_utf8(string $string): bool` function