PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » PHP » PHP_Compat » Bug #3586

bug in str_word_count.php code

Details

Submitted2005-02-24 22:53 UTC
Fromstrawman at tpdada dot art dot pl
Assignedaidan
StatusClosed
PackagePHP_Compat
PHP VersionIrrelevant
OSall
Roadmaps1.6.0a1

Comments

[2005-02-24 22:53 UTC] strawman at tpdada dot art dot pl

Description:
------------
PHP_compat, str_word_count.php, version 1.7
A bug in numbering keys when the $format = 2
$lastmatch is counted invalid, what may occur to wrong key numbering, if the next word in a string is a substring of previous
Problem fix:

There is

foreach ($word_array as $word) {
$word_assoc[$lastmatch = strpos($string, $word, $lastmatch)] = $word;
}

There should be:
foreach ($word_array as $word) {
$word_assoc[$lastmatch = strpos($string, $word, $lastmatch)] = $word;
$lastmatch+=strlen($word);
}

Hope will be useful