php比較相似字符串的方法
更新時間:2015年06月05日 09:54:57 作者:企鵝不笨
這篇文章主要介紹了php比較相似字符串的方法,通過php中similar_text函數(shù)來實現(xiàn)字符串的相似性比較功能,需要的朋友可以參考下
本文實例講述了php比較相似字符串的方法。分享給大家供大家參考。具體分析如下:
這里通過php的similar_text函數(shù)比較兩個字符串的相似性。
$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程序設(shè)計有所幫助。
相關(guān)文章
PHP將HTML轉(zhuǎn)換成文本的實現(xiàn)代碼
這篇文章主要介紹了PHP將HTML轉(zhuǎn)換成文本的實現(xiàn)代碼,需要的朋友可以參考下2015-01-01
php通過ajax實現(xiàn)雙擊table修改內(nèi)容
這篇文章主要介紹了php通過如何ajax實現(xiàn)雙擊table修改內(nèi),需要的朋友可以參考下2014-04-04
php計數(shù)排序算法的實現(xiàn)代碼(附四個實例代碼)
計數(shù)排序(Counting sort)是一種根據(jù)小整數(shù)鍵對一組對象排序的算法;也就是說,它是一個整數(shù)排序算法。它通過計算具有不同鍵值的對象的數(shù)量,并對這些數(shù)量使用算術(shù)來確定輸出序列中每個鍵值的位置2020-03-03

