[人名] 利文;[地名] [英國] 利文

php levenshtein()函數(shù) 語法

功能:計(jì)算兩個(gè)字串之間的編輯距離

語法:int?levenshtein?(?string?$str1?,?string?$str2?,?int?$cost_ins?,$cost_ins?, int?$cost_rep?,?int?$cost_del?)

#參數(shù):

##參數(shù)參數(shù)str1?str2??cost_ins
求編輯距離中的其中一個(gè)字串。
#求編輯距離中的另一個(gè)字串。
定義插入次數(shù)。

cost_rep??######定義替換次數(shù)。 ############cost_del?######定義刪除次數(shù)###################說明:###編輯距離,是指兩個(gè)字符串之間,透過替換、插入、刪除等操作將字串str1轉(zhuǎn)換成str2所需操作的最少字元數(shù)。 ###

php levenshtein()函數(shù) 範(fàn)例

<?php
$data = "hello";
$res = "world";
echo levenshtein($data,$res);
?>

運(yùn)行實(shí)例?

點(diǎn)擊"運(yùn)行實(shí)例"按鈕查看線上實(shí)例

輸出:

4


<?php
$str1 = "Learning PHP";
$str2 = "is a good choise";
echo levenshtein($str1,$str2);
?>

#執(zhí)行實(shí)例?

點(diǎn)擊"運(yùn)行實(shí)例" 按鈕查看線上實(shí)例

輸出:

14