#43993 [Ana->Asn]: mb_substr_count behaves differently to substr_count with overlapping needles

From: Date: Mon, 18 Feb 2008 09:38:23 +0000
Subject: #43993 [Ana->Asn]: mb_substr_count behaves differently to substr_count with overlapping needles
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122376@lists.php.net to get a copy of this message
ID: 43993 Updated by: jani@php.net Reported By: josmessa at uk dot ibm dot com -Status: Analyzed +Status: Assigned Bug Type: mbstring related Operating System: Windows XP SP2 PHP Version: 5.2CVS-2008-01-31 (snap) Assigned To: hirokawa New Comment: If mb_substr_count() doesn't behave like substr_count() it's a problem of mbstring, not the stock PHP function.. Previous Comments: ------------------------------------------------------------------------ [2008-02-10 00:52:45] hirokawa@php.net mb_substr_count is supporting overlapping needles. Is this a problem of substr_count ? ------------------------------------------------------------------------ [2008-01-31 17:08:52] nicholsr@php.net Assigning to extension maintainer ------------------------------------------------------------------------ [2008-01-31 14:27:02] josmessa at uk dot ibm dot com Description: ------------ In the documentation for substr_count there is a note that says: "Note: This function doesn't count overlapped substrings. See the example below! ". mb_substr_count does not replicate this behaviour, and as mb_substr_count can overload substr_count I think it should. Reproduce code: --------------- <?php $string_ascii = 'abcabcabc'; echo "mb_substr_count: "; var_dump(mb_substr_count($string_ascii, 'abcabc')); //needle overlaps in haystack echo "substr_count: "; var_dump(substr_count($string_ascii, 'abcabc')); ?> Expected result: ---------------- mb_substr_count: int(1) substr_count: int(1) Actual result: -------------- mb_substr_count: int(2) substr_count: int(1) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43993&edit=1

« previous php.bugs (#122376) next »