php比較相似字符串的方法
更新時(shí)間:2015年06月05日 09:54:57 作者:企鵝不笨
這篇文章主要介紹了php比較相似字符串的方法,通過php中similar_text函數(shù)來實(shí)現(xiàn)字符串的相似性比較功能,需要的朋友可以參考下
本文實(shí)例講述了php比較相似字符串的方法。分享給大家供大家參考。具體分析如下:
這里通過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中強(qiáng)制下載文件的代碼(解決了IE下中文文件名亂碼問題)
以下這段代碼作用是:瀏覽器提交excel格式的數(shù)據(jù)和文件名到服務(wù)器上,PHP將請(qǐng)求轉(zhuǎn)化為可下載的excel文件,并要求瀏覽器彈出文件下載提示窗口2011-05-05
php中preg_replace_callback函數(shù)簡(jiǎn)單用法示例
這篇文章主要介紹了php中preg_replace_callback函數(shù)簡(jiǎn)單用法,分析了preg_replace_callback函數(shù)的功能及簡(jiǎn)單使用方法,需要的朋友可以參考下2016-07-07

