/// must have at least three items to have a possible match if ( $array_size >= 3 ) {

$current_item = 0; $possible_match = 1;

$match_count = 0;

/// while we are not searching past the end of the array while ( $possible_match < $array_size ) {

/// while we are looking at numbers (use the ctype_alpha() if you have it compiled in) while ( !preg_match("/[a-zA-Z]/",$from[$current_item]) ) { /// we do not try to match this /// move the current_item to the one that we found which does not match $current_item = $possible_match; /// move the possible_match to the next item $possible_match++;

/// while we found a match while ( $from[$current_item] == $from[$possible_match] ) { /// tell our program we found a match $match_count++; /// if we have matched three items, two in a row if ( $match_count == 2 ) { /// obliterate this and previous item $from[$possible_match-1] = $obliterate_with; $from[$possible_match] = $obliterate_with; /// if we are matching more than two in a row } else if ( $match_count > 2 ) { /// obliterate only the one we are on $from[$possible_match] = $obliterate_with; } /// move on to check the next item $possible_match++; /// if the next possible match takes us past the end of the array if ( $possible_match >= $array_size ) { /// we are done return $from; } } /// while match

/// we are done matching this item /// set match_count back to 0 $match_count = 0; /// move the current_item to the one that we found which does not match $current_item = $possible_match; /// move the possible_match to the next item $possible_match++;

/// we need only 1 pass through the array for ( $current = 0; $current < $array_size; $current++ ) { /// if we are looking for the next alpha character to match if ( $match_to === NULL ) { /// if we we have found something to try and match if ( preg_match("/[a-zA-Z]/",$from[$current]) ) { /// set out program to attempt to match next items to this item $match_to = $current; }

/// if we are trying to match this item to a previously found one } else { /// if this item matches, we are in a sequence of like items if ( $from[$current] == $from[$match_to] ) { /// update our match count $match_count++; /// if the match_count is < $min_sequence do nothing, we need more matches, move on /// if the match_count is $min_sequence if ( $match_count == 2 ) { /// we skipped over the first few matches, so go back and obliterate them, as well as the current one for ( $i = $current; $i >= $match_to; $i-- ) { $from[$i]= $obliterate_with; }

Still far too long in my opinion. I would have used a for loop, and got it to check the $i variable, and then $i+1, and if it's the same, then $i+2, and if they're all the same, to unset $i+1 and $i+2 and move swiftly on