input answer quiz -
Posted: Wed Apr 25, 2007 8:17 am
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
}
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
}