protected function halfMatchI($longtext, $shorttext, $i)
    {
        $seed = mb_substr($longtext, $i, (int)(mb_strlen($longtext) / 4));
        $best_common = $best_longtext_a = $best_longtext_b = $best_shorttext_a = $best_shorttext_b = '';

        $j = mb_strpos($shorttext, $seed);
        while ($j !== false) {
            $prefixLegth = $this->commonPrefix(mb_substr($longtext, $i), mb_substr($shorttext, $j));
            $suffixLegth = $this->commonSuffix(mb_substr($longtext, 0, $i), mb_substr($shorttext, 0, $j));
            if (mb_strlen($best_common) < $suffixLegth + $prefixLegth) {
                $best_common = mb_substr($shorttext, $j - $suffixLegth, $suffixLegth) . mb_substr($shorttext, $j,
                        $prefixLegth);
                $best_longtext_a = mb_substr($longtext, 0, $i - $suffixLegth);
                $best_longtext_b = mb_substr($longtext, $i + $prefixLegth);
                $best_shorttext_a = mb_substr($shorttext, 0, $j - $suffixLegth);
                $best_shorttext_b = mb_substr($shorttext, $j + $prefixLegth);
            }
            $j = mb_strpos($shorttext, $seed, $j + 1);
        }


        if (mb_strlen($best_common) * 2 >= mb_strlen($longtext)) {
            return array($best_longtext_a, $best_longtext_b, $best_shorttext_a, $best_shorttext_b, $best_common);
        } else {
            return null;
        }
    }
protected function halfMatchI($longtext, $shorttext, $i)
    {
        $seed = mb_substr($longtext, $i, (int)(mb_strlen($longtext) / 4));
        $best_common = $best_longtext_a = $best_longtext_b = $best_shorttext_a = $best_shorttext_b = '';

        $j = mb_strpos($shorttext, $seed);
        while ($j !== false) {
            $prefixLegth = $this->commonPrefix(mb_substr($longtext, $i), mb_substr($shorttext, $j));
            $suffixLegth = $this->commonSuffix(mb_substr($longtext, 0, $i), mb_substr($shorttext, 0, $j));
            if (mb_strlen($best_common) < $suffixLegth + $prefixLegth) {
                $best_common = mb_substr($shorttext, $j - $suffixLegth, $suffixLegth) . mb_substr($shorttext, $j,
                        $prefixLegth);
                $best_longtext_a = mb_substr($longtext, 0, $i - $suffixLegth);
                $best_longtext_b = mb_substr($longtext, $i + $prefixLegth);
                $best_shorttext_a = mb_substr($shorttext, 0, $j - $suffixLegth);
                $best_shorttext_b = mb_substr($shorttext, $j + $prefixLegth);
            }
            $j = mb_strpos($shorttext, $seed, $j + 1);
        }


        if (mb_strlen($best_common) * 2 >= mb_strlen($longtext)) {
            return array($best_longtext_a, $best_longtext_b, $best_shorttext_a, $best_shorttext_b, $best_common);
        } else {
            return null;
        }
    }
protected function halfMatchI ( $ longtext , $ shorttext , $ i ) { $ seed = mb_substr ( $ longtext , $ i , ( int ) ( mb_strlen ( $ longtext ) / 4 ) ) ; $ best_common = $ best_longtext_a = $ best_longtext_b = $ best_shorttext_a = $ best_shorttext_b = '' ; $ j = mb_strpos ( $ shorttext , $ seed ) ; while ( $ j !== false ) { $ prefixLegth = $ this -> commonPrefix ( mb_substr ( $ longtext , $ i ) , mb_substr ( $ shorttext , $ j ) ) ; $ suffixLegth = $ this -> commonSuffix ( mb_substr ( $ longtext , 0 , $ i ) , mb_substr ( $ shorttext , 0 , $ j ) ) ; if ( mb_strlen ( $ best_common ) < $ suffixLegth + $ prefixLegth ) { $ best_common = mb_substr ( $ shorttext , $ j - $ suffixLegth , $ suffixLegth ) . mb_substr ( $ shorttext , $ j , $ prefixLegth ) ; $ best_longtext_a = mb_substr ( $ longtext , 0 , $ i - $ suffixLegth ) ; $ best_longtext_b = mb_substr ( $ longtext , $ i + $ prefixLegth ) ; $ best_shorttext_a = mb_substr ( $ shorttext , 0 , $ j - $ suffixLegth ) ; $ best_shorttext_b = mb_substr ( $ shorttext , $ j + $ prefixLegth ) ; } $ j = mb_strpos ( $ shorttext , $ seed , $ j + 1 ) ; } if ( mb_strlen ( $ best_common ) * 2 >= mb_strlen ( $ longtext ) ) { return array ( $ best_longtext_a , $ best_longtext_b , $ best_shorttext_a , $ best_shorttext_b , $ best_common ) ; } else { return null ; } }
Does a substring of shorttext exist within longtext such that the substring
is at least half the length of longtext?

@param string $longtext  Longer string.
@param string $shorttext Shorter string.
@param int    $i         Start index of quarter length substring within longtext.

@return null|array Five element array, containing the prefix of longtext, the suffix of longtext,
the prefix of shorttext, the suffix of shorttext and the common middle.  Or null if there was no match.
Does a substring of shorttext exist within longtext such that the substring is at least half the length of longtext?