我有一个表格,我可以输入两个单词,然后比较levenshtein得分,这很好。
我希望能够将1个单词与由“,”分隔的单词串进行比较。然后整个地方需要回应。这是我到目前为止所做的:
Levenstien for <b><?php echo $_POST["source"]; ?></b> and <b><?php echo $_POST["target"]; ?></b>:
<?php
$string5 = $_POST["source"];
$string6 = $_POST["target"];
$array6 = explode(', ',$string6);
echo levenshtein("$string5","$array6");
?>
答案 0 :(得分:0)
You'd use a foreach
loop(for
循环也没问题)。尝试:
Levenstien for <b><?php echo $_POST["source"]; ?></b> and <b><?php echo $_POST["target"]; ?></b>:
<?php
$string5 = $_POST["source"];
$string6 = $_POST["target"];
$array6 = explode(', ',$string6);
foreach ($array6 as $derp)
{
echo $string5, "/", $derp, ": ", levenshtein($string5, $derp), "<br>";
}
?>
要按分数顺序输出,请使用:
Levenstien for <b><?php echo $_POST["source"]; ?></b> and <b><?php echo $_POST["target"]; ?></b>:
<?php
$string5 = $_POST["source"];
$string6 = $_POST["target"];
$array6 = array_map('trim', explode(',',$string6));
$doop = array();
foreach ($array6 as $derp)
{
doop[$derp] = levenshtein($string5, $derp);
}
arsort($doop); // sorts highest element first
foreach ($words as $key => $value)
{
echo sprintf('%s / %s: %s<br />', $string5, $key, $value);
}
?>