选择语言 :

 Core_Text::similar

Finds the text that is similar between a set of words.

$match = Text::similar(array('fred', 'fran', 'free'); // "fr"

string Core_Text::similar( array $words )

参数列表

参数 类型 描述 默认值
$words array Words to find similar text of
返回值
  • string
File: ./core/classes/text.class.php
public static function similar(array $words)
{
    // First word is the word to match against
    $word = current($words);

    for($i = 0, $max = strlen($word); $i < $max; ++$i)
    {
        foreach ($words as $w)
        {
            // Once a difference is found, break out of the loops
            if ( !isset($w[$i]) || $w[$i] !== $word[$i] ) break 2;
        }
    }

    // Return the similar text
    return substr($word, 0, $i);
}