public function similarity($string = null, $cmp = null, $language = 'french')
        {
            if (empty($string) || empty($cmp)) {
                return false;
            }

            if (strlen($string) > 255 || strlen($cmp) > 255) {
                return false;
            }

            $processedStr   = $this->phoneme($string, $language);
            $processedCmp   = $this->phoneme($cmp, $language);
            $score          = levenshtein($processedStr, $processedCmp);
            $smaller        = strlen($processedStr) < strlen($processedCmp) ? $processedStr : $processedCmp;
            $biggest        = strlen($processedStr) < strlen($processedCmp) ? $processedCmp : $processedStr;

            $phonexStr      = $this->getPhonex($string);
            $phonexCmp      = $this->getPhonex($cmp);

            $scorePhonex    = ($phonexStr + $phonexCmp) / 2;

            if (empty($biggest) || empty($smaller)) {
                return false;
            }

            $contain        = strstr($biggest, $smaller);

            $avgLength      = (strlen($processedStr) + strlen($processedCmp)) / 2;
            $finalScore     = round((1.0 / $avgLength) * $score, 6);
            $finalScore     = round(((1 - $finalScore) * 100), 2);

            $finalScore     = 0 > $finalScore && false !== $contain ? 100 + $finalScore : $finalScore;
            $finalScore     = 100 < $finalScore ? 100   : $finalScore;
            $finalScore     = 0 > $finalScore   ? 0     : $finalScore;

            if ($finalScore / 100 >= $this->_tolerance) {
                $grade = 1;
            } else {
                $grade = 0;
            }

            $proxMatch  = self::checkProx(self::_iconv($string), self::_iconv($cmp));
            $pctg       = $finalScore > $proxMatch ? $finalScore : $proxMatch;

            if (strstr($string, ' ') && strstr($cmp, ' ')) {
                $matchWords = self::matchWords(self::_iconv($string), self::_iconv($cmp));
                $pctg       = $matchWords > $pctg ? $matchWords : $pctg;
            }

            $finalScore  = $pctg > $finalScore ? $pctg : $finalScore;


            $data = array(
                'cost'      =>  $score,
                'score'     =>  $finalScore,
                'similar'   =>  $grade
            );

            return $data;
        }
public function similarity($string = null, $cmp = null, $language = 'french')
        {
            if (empty($string) || empty($cmp)) {
                return false;
            }

            if (strlen($string) > 255 || strlen($cmp) > 255) {
                return false;
            }

            $processedStr   = $this->phoneme($string, $language);
            $processedCmp   = $this->phoneme($cmp, $language);
            $score          = levenshtein($processedStr, $processedCmp);
            $smaller        = strlen($processedStr) < strlen($processedCmp) ? $processedStr : $processedCmp;
            $biggest        = strlen($processedStr) < strlen($processedCmp) ? $processedCmp : $processedStr;

            $phonexStr      = $this->getPhonex($string);
            $phonexCmp      = $this->getPhonex($cmp);

            $scorePhonex    = ($phonexStr + $phonexCmp) / 2;

            if (empty($biggest) || empty($smaller)) {
                return false;
            }

            $contain        = strstr($biggest, $smaller);

            $avgLength      = (strlen($processedStr) + strlen($processedCmp)) / 2;
            $finalScore     = round((1.0 / $avgLength) * $score, 6);
            $finalScore     = round(((1 - $finalScore) * 100), 2);

            $finalScore     = 0 > $finalScore && false !== $contain ? 100 + $finalScore : $finalScore;
            $finalScore     = 100 < $finalScore ? 100   : $finalScore;
            $finalScore     = 0 > $finalScore   ? 0     : $finalScore;

            if ($finalScore / 100 >= $this->_tolerance) {
                $grade = 1;
            } else {
                $grade = 0;
            }

            $proxMatch  = self::checkProx(self::_iconv($string), self::_iconv($cmp));
            $pctg       = $finalScore > $proxMatch ? $finalScore : $proxMatch;

            if (strstr($string, ' ') && strstr($cmp, ' ')) {
                $matchWords = self::matchWords(self::_iconv($string), self::_iconv($cmp));
                $pctg       = $matchWords > $pctg ? $matchWords : $pctg;
            }

            $finalScore  = $pctg > $finalScore ? $pctg : $finalScore;


            $data = array(
                'cost'      =>  $score,
                'score'     =>  $finalScore,
                'similar'   =>  $grade
            );

            return $data;
        }
public function similarity ( $ string = null , $ cmp = null , $ language = 'french' ) { if ( empty ( $ string ) || empty ( $ cmp ) ) { return false ; } if ( strlen ( $ string ) > 255 || strlen ( $ cmp ) > 255 ) { return false ; } $ processedStr = $ this -> phoneme ( $ string , $ language ) ; $ processedCmp = $ this -> phoneme ( $ cmp , $ language ) ; $ score = levenshtein ( $ processedStr , $ processedCmp ) ; $ smaller = strlen ( $ processedStr ) < strlen ( $ processedCmp ) ? $ processedStr : $ processedCmp ; $ biggest = strlen ( $ processedStr ) < strlen ( $ processedCmp ) ? $ processedCmp : $ processedStr ; $ phonexStr = $ this -> getPhonex ( $ string ) ; $ phonexCmp = $ this -> getPhonex ( $ cmp ) ; $ scorePhonex = ( $ phonexStr + $ phonexCmp ) / 2 ; if ( empty ( $ biggest ) || empty ( $ smaller ) ) { return false ; } $ contain = strstr ( $ biggest , $ smaller ) ; $ avgLength = ( strlen ( $ processedStr ) + strlen ( $ processedCmp ) ) / 2 ; $ finalScore = round ( ( 1.0 / $ avgLength ) * $ score , 6 ) ; $ finalScore = round ( ( ( 1 - $ finalScore ) * 100 ) , 2 ) ; $ finalScore = 0 > $ finalScore && false !== $ contain ? 100 + $ finalScore : $ finalScore ; $ finalScore = 100 < $ finalScore ? 100 : $ finalScore ; $ finalScore = 0 > $ finalScore ? 0 : $ finalScore ; if ( $ finalScore / 100 >= $ this -> _tolerance ) { $ grade = 1 ; } else { $ grade = 0 ; } $ proxMatch = self :: checkProx ( self :: _iconv ( $ string ) , self :: _iconv ( $ cmp ) ) ; $ pctg = $ finalScore > $ proxMatch ? $ finalScore : $ proxMatch ; if ( strstr ( $ string , ' ' ) && strstr ( $ cmp , ' ' ) ) { $ matchWords = self :: matchWords ( self :: _iconv ( $ string ) , self :: _iconv ( $ cmp ) ) ; $ pctg = $ matchWords > $ pctg ? $ matchWords : $ pctg ; } $ finalScore = $ pctg > $ finalScore ? $ pctg : $ finalScore ; $ data = array ( 'cost' => $ score , 'score' => $ finalScore , 'similar' => $ grade ) ; return $ data ; }
Compare 2 strings to see how similar they are.

@param string $string The first string to compare. Max length of 255 chars.
@param string $cmp The second string to comapre against the first. Max length of 255 chars.
@param string $language The language to make phonemes
@return mixed false if $string or $cmp is empty or longer then 255 chars, the max length for a PHP levenshtein.
Compare 2 strings to see how similar they are .