文の比較について助けが必要です。
$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文字列では、正しく、括弧で囲まれています。このため、これらの単語がユーザーの応答に対してカウントされないようにします。したがって、ユーザーがこれらの単語を持っている場合、それはそれらに対してカウントされません。そして、ユーザーがこれらの単語を持っていない場合、それはそれらに対してカウントされません。
これは可能ですか?