Skip to content

Commit 380966d

Browse files
committed
Strings::length() uses mbstring, iconv and then utf8_decode [Closes #299]
1 parent dd7502e commit 380966d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Utils/Strings.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ public static function findPrefix(array $strings): string
397397
*/
398398
public static function length(string $s): int
399399
{
400-
return function_exists('mb_strlen')
401-
? mb_strlen($s, 'UTF-8')
402-
: strlen(utf8_decode($s));
400+
return match (true) {
401+
extension_loaded('mbstring') => mb_strlen($s, 'UTF-8'),
402+
extension_loaded('iconv') => iconv_strlen($s, 'UTF-8'),
403+
default => strlen(@utf8_decode($s)), // deprecated
404+
};
403405
}
404406

405407

0 commit comments

Comments
 (0)