如何使帖子有多个答案? 如果我能弄清楚如何使其不对大写字母敏感,那也会很有帮助。
下面是一个示例:
$a = "What is the color of the sky?"
if($_POST['ans'] == "blue") {
echo "Correct!";
}
形式:
<form method="POST" action="">
<input type="text" name="answers" /><br />
<input type="submit" />
</form>
我试过了
if($_POST['ans'] == "blue" . "Blue") {
echo "Correct!";
}
和
if($_POST['ans'] == "blue" or "Blue") {
echo "Correct!";
}
您可以使用strcasecmp在PHP中进行不区分大小写的字符串比较。
<?php
if (strcasecmp($_POST['ans'], 'blue') == 0) {
echo 'Correct!';
}
?>
您可以使用 strtolower 将所有字符串转换为小写,因此 bLuE 将为蓝色
<?php
if (strtolower($_POST['ans'] == 'blue')) {
echo 'Correct!';
}
?>