Page 1 of 1

input answer quiz -

Posted: Wed Apr 25, 2007 8:17 am
by vincerosso
HI

I have tried to make the input answer quiz a little more tolerant by changing the answer comparison code.

I am not very experienced at PHP so I apologize in advance if I have made any 'rookie' mistakes.

Needless to say my modified Quiz produces no output...

Could anyone tell me what I have done wrong??

---------------------------------------------------------------------
I have changed (in quiz.php)

if(strtolower($user_answer) == strtolower($actual_answer))

to

if(inStr(strtolower($actual_answer), strtolower($user_answer))


and I have added the 'instring' function (in \includes\functions.quiz.php

function inStr ($needle, $haystack)
{
$needlechars = strlen($needle); //gets the number of characters in our needle
$i = 0;
for($i=0; $i < strlen($haystack); $i++) //creates a loop for the number of characters in our haystack
{
if(substr($haystack, $i, $needlechars) == $needle) //checks to see if the needle is in this segment of the haystack
{
return TRUE; //if it is return true
}
}
return FALSE; //if not, return false
}

Posted: Wed Apr 25, 2007 9:00 am
by battye
Are you trying to allow more answers, for instance:

The real answer is "Beatles", but someone inputs "The Beatles" and have it seen as a correct answer? I assume that is what you want to achieve by checking for the needle in a haystack.

Posted: Thu Apr 26, 2007 5:37 pm
by vincerosso
battye wrote:Are you trying to allow more answers, for instance:

The real answer is "Beatles", but someone inputs "The Beatles" and have it seen as a correct answer? I assume that is what you want to achieve by checking for the needle in a haystack.
Thats correct.....

is my code correct because all I get is a blank screen when I modify the code.....