- MFH: Fixed bug #43993 (mb_substr_count() behaves differently to substr_count() with overlapping needles)

This commit is contained in:
Moriyoshi Koizumi 2008-08-01 22:56:47 +00:00
parent c123d7fea0
commit 98b5795702
2 changed files with 27 additions and 0 deletions

View File

@ -1013,6 +1013,7 @@ mbfl_substr_count(
if (pc.matched_pos >= 0) {
++result;
pc.matched_pos = -1;
pc.needle_pos = 0;
}
n--;
}

View File

@ -0,0 +1,26 @@
--TEST--
Bug #43993 (mb_substr_count() behaves differently to substr_count() with overlapping needles)
--SKIPIF--
<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
--FILE--
<?php
var_dump(mb_substr_count("abcabcabca", "abcabc"));
var_dump(mb_substr_count("abcabcabca", "abc"));
var_dump(mb_substr_count("abcabcabca", "cab"));
var_dump(mb_substr_count("abcabcabca", "bca"));
var_dump(mb_substr_count("ababababab", "ba"));
var_dump(mb_substr_count("ababababab", "ab"));
var_dump(mb_substr_count("ababababab", "bc"));
var_dump(mb_substr_count("aaaaaaaaaa", "a"));
var_dump(mb_substr_count("aaaaaaaaaa", "b"));
?>
--EXPECT--
int(1)
int(3)
int(2)
int(3)
int(4)
int(5)
int(0)
int(10)
int(0)