How to calculate similarity (in percentage) between strings in PHP?

1

I would like to know how to calculate the similarity, in percentage, between two strings with PHP?

For example:

  • I have a gift for you!
  • I want some of you gifts!
asked by anonymous 23.09.2015 / 18:17

1 answer

1

The best native form of PHP itself is this:

$var_1 = 'Eu tenho um presente pra vocês!'; 
$var_2 = 'Eu quero alguns presentes de vocês!'; 

similar_text($var_1, $var_2, $percentual); 

echo $percentual; 
// 73.529411764706 

Demo: link

    
23.09.2015 / 18:17