-5

How do I make a post have multiple answers? And it would also be helpful if I could figure out how to make it non-caps sensitive.

Here is an example:

$a = "What is the color of the sky?"

if($_POST['ans'] == "blue")  {
   echo "Correct!";
}

form:

<form method="POST" action="">
<input type="text" name="ans" /><br />
<input type="submit" />
</form>

I have tried

if($_POST['ans'] == "blue" . "Blue")  {
   echo "Correct!";
}

And

if($_POST['ans'] == "blue" or "Blue")  {
       echo "Correct!";
}
4

2 回答 2

2

You can do the case-insensitive string comparison in PHP by using strcasecmp.

<?php
    if (strcasecmp($_POST['ans'], 'blue') == 0) {
        echo 'Correct!';
    }
?>
于 2013-11-05T00:49:04.570 回答
0

You can use strtolower which turns all string to lower case, so bLuE will be blue

<?php
    if (strtolower($_POST['ans'] == 'blue')) {
        echo 'Correct!';
    }
?>
于 2013-11-05T01:06:02.673 回答