input answer quiz -

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Post Reply
vincerosso
Greenhorn
Greenhorn
Posts: 4
Joined: Fri Apr 20, 2007 10:50 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
}
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

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.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
vincerosso
Greenhorn
Greenhorn
Posts: 4
Joined: Fri Apr 20, 2007 10:50 am

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.....
Post Reply