我需要一些與句子比較的幫助。句子比較:忽略單詞
$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字符串中,正確,而位於括號內 - 因此,我不希望這些單詞再次計算用戶的回覆。因此,如果用戶擁有這些詞語,則不會對他們進行計數。如果用戶沒有這些詞,那麼它就不算對他們。
這可能嗎?
做什麼'$ answer'和'$ response'包含後您的' preg_replace'功能?看起來你已經剝離出任何不是字母數字和空格的東西。 – Kyle 2013-03-25 17:29:32
_Count反對他們_我的意思是它不會改變相似性百分比。所以,如果用戶有或沒有加括號的單詞,它不會改變百分比。但是,如果他們沒有不加括號的內容,會影響相似性百分比。 – Dutchcoffee 2013-03-25 17:32:08
** $ answer:**'這是可以接受的答案如果不存在於用戶的答案中,則括號內的內容將被忽略如果它存在,則不應該對它們進行計數** ** $ response:**'這是正確和可接受的答案如果不存在於用戶的答案中,則括號內的內容將被忽略如果它存在,則不應該對它們進行計數「 – Dutchcoffee 2013-03-25 17:34:27