给你,这段代码基于similar_text() php函数,我可以看到它通过字母而不是整个单词来比较字符串,看例子:
<?php
if(isset($_REQUEST["str_a"]) && isset($_REQUEST["str_b"])) {
$str_a = $_REQUEST["str_a"];
$str_b = $_REQUEST["str_b"];
function compare_them($str_1, $str_2) {
$str_1 = trim(strtolower($str_1));
$str_2 = trim(strtolower($str_2));
similar_text($str_1, $str_2, $percentage);
$formated_percents = number_format($percentage);
return $formated_percents;
}
$calculated = compare_them($str_a, $str_b);
}
?>
<form action="" method="get">
string a: <input type="text" value="" name="str_a" />
<br />
string b: <input type="text" value="" name="str_b" />
<br />
<br />
<input type="submit" value="submit" />
</form>
<h2>
<?php
if(isset($_REQUEST["str_a"]) && isset($_REQUEST["str_b"])) {
print "string a = " . $str_a . " <br />string b = " . $str_b . " <br />percents match = " . $calculated . "%";
}
?>
</h2>
这是现场示例:
http ://simplestudio.rs/yard/percent/percent.php