php关于字符串的处理(考试多选题),有点难

我数据库里面 存着答案 ABCD这个字符串,
但是用户输入 BCAD 明明是正确的 却得不到分,
这个怎么比较 可以实现

$key='ABCD';

$answer='BCAD';
让这两个字符串比较起来 是一样的呢?

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<form action="" method="post" >
     正确答案:<input type="text" name='answer'>
        答  案   :<input type="text" name="stuanswer">
        <input type="submit" value="比较答案">
    </form>
   <?php
   if(isset($_POST['answer'])&&isset($_POST['stuanswer'])&&$_POST['answer']!=''&&$_POST['stuanswer']!=''){
$str=$_POST['answer'];
$str1=$_POST['stuanswer'];
if(strlen($str1)==strlen($str)){
$count=strlen($str);
for($i=0;$i<$count;$i++){
if(!strstr($str1,$str[$i])||!strstr($str,$str1[$i])){
echo "<script> alert('答案错误');</script>";
exit;
}
}echo "<script> alert('答案正确');</script>";
}else{
echo "<script> alert('答案错误');</script>";
}
   }
?>
<body>
</body>
</html>

 //来试试这个代码,正则我不会,只能写这样的代码,你可以测试,我测试结果没有问题

温馨提示:答案为网友推荐,仅供参考
相似回答