我想創建一個函數,在用戶帳戶中存在多次蠻力嘗試時會提醒用戶。如果字符串匹配超過75%,該函數將提醒用戶。我已經執行了這個:如何獲得兩個字符串之間的相似度?
function Password_Match ($String, $Stored_Password){
$New_String = str_split($String);
$New_Stored_Password = str_split($Stored_Password);
$Match = 0;
foreach ($New_String AS $Value){
if (in_array($Value,$New_Stored_Password)){
$Match++;
}
}
return $Match;
}
$String = "Test";
$Pass = "Tesst";
echo Password_Match($String,$Pass);
這返回4,但我的代碼中顯然存在一個缺陷,我找不出解決方案。分心會很棒。
你說的是「字符串匹配」,好像有一個通用的定義。 – Jon
[php相似的文本](http://php.net/manual/en/function.similar-text.php) – amigura
該函數只是確定一個字符串的字符是否存在於另一個字符串中。然而,它並不關心位置,也不關心重複。所以'aaaaaa'和'abcdef'據說有6個匹配,因爲'aaaaaa'中的每個'a'出現在'abcdef'中。 – Gumbo