W dniu 11.02.2022 o 16:41, Kirill Nesmeyanov pisze:
```
$string = ‘Hell 😁 or 😎 world!’;
echo ‘Bytes: ’ . \strlen($string) . "\n";
echo ‘Chars: ‘ . \mb_strlen($string);
```
Thanks Kirill for Your answer.
I totally agree that stream and text functions are two different things.
However, in the context of cleaning up the PHP language, the
inconsistency is very disturbing. Considering the given example, the
description from the documentation of strlen function: "Returns the
length of the given string". Only below that you can find the note that
function "returns the number of bytes". So strlen is in the virtual
namespace String (String functions), its description says that it should
return the length of the string, but if you specify a multibyte string
it returns the number of bytes, not the number of characters. In that
case there should be a bytes_length function, or something like
Stream::fromString(string $string)->getSize(); (StreamInterface from
PSR-7 is also a great example). So, using the example given, a natural
and logical approach would be:
```
$string = ‘Hell 😁 or 😎 world!’;
echo ‘Bytes: ’ . \bytes_length($string) . "\n";
echo ‘Chars: ‘ . \strlen($string); // in that case alias for mb_strlen
```
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php