!DOCTYPE html>
html>
head>
meta charset="UTF-8">
title>php计算器/title>
/head>
body>
form name="form" method="post" action="phpjisuan.php">
请输入num1:input type="text" name="num1">/br>/br>
请选择运算符:select name="sel">
option value="+">+/option>
option value="-">-/option>
option value="*">*/option>
option value="/">//option>
option value="%">%/option>
/select>/br>/br>
请输入num2:input type="text" name="num2">/br>/br>
input type="submit" name="Submit" value="计算">
input type="reset" name="Reset" value="重置">
/form>
/body>
/html>
!DOCTYPE html>
html>
head>
meta charset="UTF-8">
title>php计算器/title>
?php
$num1=$_POST["num1"];
$num2=$_POST["num2"];
$sel=$_POST["sel"];
?>
/head>
body>
?php
if($sel=="+"){
$num=$num1+$num2;
}
else if($sel=="-"){
$num=$num1-$num2;
}
else if($sel=="*"){
$num=$num1*$num2;
}
else if($sel=="/"){
if($num2!=0){
$num=$num1/$num2;
}else{
echo "除数不能为0";
}
}
else if($sel=="%"){
if($num2!=0){
$num=$num1%$num2;
}else{
echo "除数不能为0";
}
}
if(isset($num)){
echo "运算结果为$num";
}
?>
/body>
/html>