我需要一些关于句子比较的帮助。
$answer = "This is the (correct and) acceptable answer. Content inside the parenthesis are ignored if not present in the user's answer. If it is present, it should not count against them.";
$response = "This is the correct and acceptable answer. Content inside the parenthesis are ignored if not present in the user's answer. If it is present, it should not count against them.";
echo "<strong>Acceptable Answer:</strong>";
echo "<pre style='white-space:normal;'>$answer</pre><hr/>";
echo "<strong>User's Answer:</strong>";
echo "<pre>".$response."</pre>";
// strip content in brackets
$answer = preg_replace("/\([^)]*\)|[()]/", "", $answer);
// strip punctuation
$answer = preg_replace("/[^a-zA-Z 0-9]+/", " ", $answer);
$response = preg_replace("/[^a-zA-Z 0-9]+/", " ", $response);
$common = similar_text($answer, $response, $percent);
$orgcount = strlen($answer);
printf("The user's response has %d/$orgcount characters in common (%.2f%%).", $common, $percent);
基本上我想做的是忽略带括号的单词。例如,在 $answer 字符串中,正确并在括号中 - 因此,我不希望这些词再次计入用户的响应。因此,如果用户有这些词,则不计入它们。如果用户没有这些词,则不计入它们。
这可能吗?