<!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>
//来试试这个代码,正则我不会,只能写这样的代码,你可以测试,我测试结果没有问题