php 通过 similar_text函数比较两个字符串相似程度
内容摘要
这篇文章主要为大家详细介绍了php 通过 similar_text函数比较两个字符串相似程度,具有一定的参考价值,可以用来参考一下。
本代码演示了如何通过php的 similar_text函数比较
本代码演示了如何通过php的 similar_text函数比较
文章正文
这篇文章主要为大家详细介绍了php 通过 similar_text函数比较两个字符串相似程度,具有一定的参考价值,可以用来参考一下。
本代码演示了如何通过php的 similar_text函数比较两个字符串的相似性,php比较相似字符串,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <code class = "php" > /** * 通过 similar_text函数比较两个字符串的相似性 * * @param * @arrange (www.idcnote.com) **/ $word2compare = "stupid" ; $words = array ( 'stupid' , 'stu and pid' , 'hello' , 'foobar' , 'stpid' , 'upid' , 'stuuupid' , 'sstuuupiiid' , ); while (list( $id , $str ) = each( $words )){ similar_text( $str , $word2compare , $percent ); print "Comparing '$word2compare' with '$str': " ; print round ( $percent ) . "%\n" ; } /* Results: Comparing 'stupid' with 'stupid': 100% Comparing 'stupid' with 'stu and pid': 71% Comparing 'stupid' with 'hello': 0% Comparing 'stupid' with 'foobar': 0% Comparing 'stupid' with 'stpid': 91% Comparing 'stupid' with 'upid': 80% Comparing 'stupid' with 'stuuupid': 86% Comparing 'stupid' with 'sstuuupiiid': 71% */ /*** 代码来自php教程(www.idcnote.com) ***/ </code> |
注:关于php 通过 similar_text函数比较两个字符串相似程度的内容就先介绍到这里,更多相关文章的可以留意
代码注释