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
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
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
}
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.