我需要能够比较2个字符串,例如string1“ qwerty1234”和string2“ qwerty5678”,并能够确定string2是否至少从string1更改了4个字符。
例如:qwerty1234和qwerty1235仅具有1个字符的更改。qwerty1234和qwerty5678的字符更改为4。qwerty1234和qazxcv1234的字符更改为4。qwerty1234和qwerty具有4个字符的更改。qwerty1234和asdf123%^&至少有4个字符的更改。
if (strcmp($cur_password, $new_password) <= 3)
{
echo "Your new password is too similiar to your old password!"
echo "There must be at least a 4 character difference. Try again."
break;
}
任何帮助将不胜感激。
谢谢!
您可以使用以下levenstein
功能获得不同之处:
在莱文斯坦距离被定义为必须更换,插入或删除转换的字符的最小数量
str1
成str2
。
代码:
$s1 = 'qwerty1234';
$s2 = 'qwerty5678';
echo levenshtein ($s1, $s2); // => 4
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句