php比較相似字符串的方法
本文實(shí)例講述了php比較相似字符串的方法。分享給大家供大家參考。具體分析如下:
這里通過(guò)php的similar_text函數(shù)比較兩個(gè)字符串的相似性。
$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%
*/
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP將HTML轉(zhuǎn)換成文本的實(shí)現(xiàn)代碼
這篇文章主要介紹了PHP將HTML轉(zhuǎn)換成文本的實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-01-01
php 采集書并合成txt格式的實(shí)現(xiàn)代碼
記得上次有過(guò)一個(gè)叫采集后的處理這個(gè)就是它的升級(jí)版本 連采再處理,合成一本書txt的。2009-03-03
php mssql 數(shù)據(jù)庫(kù)分頁(yè)SQL語(yǔ)句
php mssql幾條常見的數(shù)據(jù)庫(kù)分頁(yè) SQL 語(yǔ)句2008-12-12
php通過(guò)ajax實(shí)現(xiàn)雙擊table修改內(nèi)容
這篇文章主要介紹了php通過(guò)如何ajax實(shí)現(xiàn)雙擊table修改內(nèi),需要的朋友可以參考下2014-04-04
php計(jì)數(shù)排序算法的實(shí)現(xiàn)代碼(附四個(gè)實(shí)例代碼)
計(jì)數(shù)排序(Counting sort)是一種根據(jù)小整數(shù)鍵對(duì)一組對(duì)象排序的算法;也就是說(shuō),它是一個(gè)整數(shù)排序算法。它通過(guò)計(jì)算具有不同鍵值的對(duì)象的數(shù)量,并對(duì)這些數(shù)量使用算術(shù)來(lái)確定輸出序列中每個(gè)鍵值的位置2020-03-03
Ajax+PHP快速上手及簡(jiǎn)單應(yīng)用說(shuō)明
對(duì)于Ajax,最核心的一個(gè)對(duì)象是XMLHttpRequest,所有的Ajax操作都離不開對(duì)這個(gè)對(duì)象的操作2013-07-07
PHP動(dòng)態(tài)柱狀圖實(shí)現(xiàn)方法
這篇文章主要介紹了PHP動(dòng)態(tài)柱狀圖實(shí)現(xiàn)方法,實(shí)例分析了php結(jié)合HTML元素實(shí)現(xiàn)動(dòng)態(tài)柱狀圖的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03

