0
I would like to know how to compare a phrase inserted by the user with those in the BD in order to return the probability of being similar. I have a similar code that compares two strings in JAVA but needed to do it in PHP+Mysql
0
I would like to know how to compare a phrase inserted by the user with those in the BD in order to return the probability of being similar. I have a similar code that compares two strings in JAVA but needed to do it in PHP+Mysql
3
The strcasecmp function compares two strings without case differentiation.
$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 differentiating uppercase and lowercase.
//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
}
3
There is the function similar_text(), it 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.
Browser other questions tagged php mysql html5
You are not signed in. Login or sign up in order to post.
http://androidaddicted.wordpress.com/2010/06/01/jaro-winkler-sql-code/ Jaro Winkler works well on Oracle
– Motta
the goal is to compare the inserted phrase with the ones already in the database and return the similarity. Have idea of how I can develop the code?
– rockie
@Rockie, I believe that you will need to prepare a query that compares the new phrase with all that already exist in the database, in the end it should return the greatest similarity. In Postgres I know a few ways to do this, but as I worked very little with Mysql, in it I don’t know the native functions.
– Marcio Mazzucato