How to compare an inserted phrase with those in the DB returning the probability of being similar?

0

I would like to know how to compare a phrase entered by the user with the phrase in the DB so that it returns the probability of being similar. I have a similar code that compares two strings in JAVA but needed to do it in PHP + MySQL

    
asked by anonymous 07.11.2014 / 13:23

2 answers

3

The strcasecmp function compares two strings that are not case-sensitive.

$var1 = 'A';
$var2 = 'a';

//comparacao case insensitive
if(strcasecmp($var1, $var2) == 0) {

    echo $var1.' (igual) '.$var2; //Imprime 'A igual a'
}

The strcmp function compares two strings that are case-sensitive.

//comparacao case sensitive
if(strcmp($var1, $var2) != 0) {

    echo $var1.' (diferente) '.$var2; //Imprime 'A diferente de a'
}

$var1 = 'A';
$var2 = 'B';

//comparacao case sensitive
if(strcmp($var1, $var2) != 0) {

    echo $var1.' (diferente) '.$var2; //Imprime 'A diferente de B
}
    
07.11.2014 / 13:46
3

The similar_text () function calculates the similarity between two strings, for example :

similar_text('Olá mundo', 'Oi Mundo', $percentualSimilaridade);
echo 'Percentual de similaridade: ' . $percentualSimilaridade; // Imprime 66.6666666667

That is, the two sentences have approximately 66.67% similarity.

    
07.11.2014 / 17:01