如何匹配相似的单词?

时间:2012-12-14 04:15:18

标签: php javascript jquery database

我有这样的形式=

Name 1
First Name  :  <input type='text' name='firstname'>
Middle Name :  <input type='text' name='middlename'>
Last Name   :  <input type='text' name='lastname'>


Name 2
First Name  :  <input type='text' name='firstname2'>
Middle Name :  <input type='text' name='middlename2'>
Last Name   :  <input type='text' name='lastname2'>

当输入“名称1”和“名称2”时,我想要这样的结果:

`example : <br>
 Name 1 = michael smith <br>
 Name 2 = michael nick smith <br>
 Percentage similar of "Name 1" and "Name 2" is = 80% `  

请帮帮我

1 个答案:

答案 0 :(得分:0)

仅使用此http://www.php.net/manual/en/function.similar-text.php这就是您所需要的。

$var_1 = 'PHP IS GREAT'; 
$var_2 = 'WITH MYSQL'; 

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

echo $percent; 
// 27.272727272727 

代码的实时示例http://codepad.viper-7.com/nyHukz

$var_1 = 'michael smith'; 
$var_2 = 'michael nick smith'; 

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

echo $percent; 
//83.870967741935