[人名] Leven;[地名] [イギリス] Leven

PHPレーベンシュテイン()関數(shù) 構(gòu)文

関數(shù):2 つの文字列間の編集距離を計(jì)算します

構(gòu)文: int levenshtein (string $str1, string $str2, int $cost_ins, int $cost_rep , int $cost_del )

パラメータ:

パラメータ説明
str1 編集距離內(nèi)の文字列の 1 つを検索します。
str2 編集距離內(nèi)の別の文字列を検索します。
cost_ins挿入數(shù)を定義します。
cost_rep 置換の數(shù)を定義します。
cost_del 削除數(shù)を定義します

注: 編集距離は參照しますto 2 つの文字列の間で、置換、挿入、削除などの操作によって文字列 str1 を str2 に変換するために必要な最小文字?jǐn)?shù)。

PHPレーベンシュテイン()関數(shù) 例

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

インスタンスの実行>>

[インスタンスの実行] ボタンをクリックしてオンライン インスタンスを表示します

出力:

4


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

インスタンスの実行?

[インスタンスの実行] ボタンをクリックして、オンライン インスタンスを表示

出力:

14