문장 비교에 도움이 필요합니다.문장 비교 : 단어 무시
$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);
기본적으로 내가 원하는 것은 parenthiseised 단어를 무시하는 것입니다. 예를 들어, $ 응답 문자열에 이 정확하고이 괄호 안에 있습니다.이 때문에이 단어가 사용자의 응답을 다시 계산하는 것을 원하지 않습니다. 따라서 사용자가이 단어를 사용하면 해당 단어는 포함되지 않습니다. 그리고 사용자가이 단어들을 가지고 있지 않다면, 그것들에 포함되지 않습니다.
이것이 가능합니까?
이 후 포함 당신' preg_replace' 함수? 당신이 이미 영숫자와 공간이 아닌 것을 제거하고있는 것처럼 보입니다. – Kyle
_ 그 (것)들에 대하여 계산하십시오 나는 유사성 백분율을 바꾸지 않을 것이라는 점을 의미한다. 따라서 사용자가 괄호 안에있는 단어를 가지고 있거나 갖지 않으면 백분율이 변경되지 않습니다. 그러나 괄호 안의 값을 갖지 않으면 유사 율에 영향을줍니다. – Dutchcoffee
** $ answer : **'이것은 수용 가능한 대답입니다. 괄호 안의 내용은 사용자의 대답에없는 경우 무시됩니다. 대답이있는 경우에는 해당 항목에 대해 계산해서는 안됩니다. '** $ response : **'이것은 정확하고 수용 가능한 대답 괄호 안의 내용은 사용자 응답에 존재하지 않는다면 무시됩니다. 존재한다면 그것들에 대해 계산해서는 안됩니다. ' – Dutchcoffee