Skip to content

Commit

Permalink
[+]: try to fix "UTF8::substr_count()" for PHP 7.1 v3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Apr 7, 2017
1 parent f3c7280 commit e075f41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/voku/helper/UTF8.php
Original file line number Diff line number Diff line change
Expand Up @@ -6447,6 +6447,12 @@ public static function substr_count($haystack, $needle, $offset = 0, $length = n
$length = (int)$length;

if (
(
$length !== 0
&&
$offset !== 0
)
&&
$length + $offset <= 0
&&
Bootup::is_php('7.1') === false // output from "substr_count()" have changed in PHP 7.1
Expand Down
3 changes: 2 additions & 1 deletion tests/Utf8GlobalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,8 @@ public function testSubstrCount()
self::assertSame(false, UTF8::substr_count('', '文空'));
self::assertSame(false, UTF8::substr_count('中文空白', ''));
self::assertSame(false, UTF8::substr_count('', ''));
self::assertSame(false, UTF8::substr_count('中文空白', '文空', 0, 0));

self::assertSame(0, UTF8::substr_count('中文空白', '文空', 0, 0));

self::assertSame(0, UTF8::substr_count('中文空白', '文空', 0, 1));
self::assertSame(1, UTF8::substr_count("○●◎\r", '●◎', 1, 2));
Expand Down

0 comments on commit e075f41

Please sign in to comment.