Skip to content

Commit 422300b

Browse files
committed
[+]: fix for "substr_compare" + different results with different PHP versions :/ v2
1 parent 8442f91 commit 422300b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/voku/helper/UTF8.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11878,10 +11878,25 @@ public static function substr_compare(
1187811878
||
1187911879
$length !== null
1188011880
) {
11881-
$encoding = self::normalize_encoding($encoding, 'UTF-8');
11881+
if ($encoding === 'UTF-8') {
11882+
if (\PHP_VERSION_ID < 70400) {
11883+
if ($length === null) {
11884+
$str1 = (string) \mb_substr($str1, $offset);
11885+
} else {
11886+
$str1 = (string)\mb_substr($str1, $offset, $length);
11887+
}
1188211888

11883-
$str1 = (string) self::substr($str1, $offset, $length, $encoding);
11884-
$str2 = (string) self::substr($str2, 0, (int) self::strlen($str1), $encoding);
11889+
$str2 = (string) \mb_substr($str2, 0, (int) self::strlen($str1), $encoding);
11890+
} else {
11891+
$str1 = (string) self::substr($str1, $offset, $length, $encoding);
11892+
$str2 = (string) self::substr($str2, 0, (int) self::strlen($str1), $encoding);
11893+
}
11894+
} else {
11895+
$encoding = self::normalize_encoding($encoding, 'UTF-8');
11896+
11897+
$str1 = (string) self::substr($str1, $offset, $length, $encoding);
11898+
$str2 = (string) self::substr($str2, 0, (int) self::strlen($str1), $encoding);
11899+
}
1188511900
}
1188611901

1188711902
if ($case_insensitivity) {

0 commit comments

Comments
 (0)