php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43993 mb_substr_count behaves differently to substr_count with overlapping needles
Submitted: 2008-01-31 14:27 UTC Modified: 2008-08-01 23:00 UTC
From: josmessa at uk dot ibm dot com Assigned: hirokawa (profile)
Status: Closed Package: mbstring related
PHP Version: 5.2CVS-2008-01-31 (snap) OS: Windows XP SP2
Private report: No CVE-ID: None
 [2008-01-31 14:27 UTC] 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)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-18 09:38 UTC] jani@php.net
If mb_substr_count() doesn't behave like substr_count() it's a problem of mbstring, not the stock PHP function..
 [2008-08-01 23:00 UTC] moriyoshi@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

It is a shame that this kind of bug wasn't found for a long time..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 08:01:29 2024 UTC