PHP form表单计算器 For html美化

代码语言:javascript
复制
<html>
	<head>
		<meta charset="UTF-8">
	<style>
#zm{
				margin:0 auto; /*块居中*/
				height:200px;/*块高*/
				width:500px;/*块宽*/
				box-shadow:0 10px 50px 5px rgba(9,99,25,.88);/*设置阴影*/
				margin-top:100px;/*顶部边距*/
				border-radius:10px;/*块圆角值*/
				}
#img{
				float: left;		/*居左显示*/
				width: 110px;		/*图片宽*/
				margin-top: 20px;	/*img距离盒子顶部边距*/
				margin-left: 30px;	/*img距离盒子左侧边距*/
				}
#p 	{
				margin-left: 160px;/*文字距离盒子左侧的距离*/
				line-height:30px/*行距*/
			}

#zm2{
margin-top: 20px;
margin-left: 20px;/文字距离盒子左侧的距离/
font-size:14px;/字号/
line-height:1.5;/行距/
color:#919191/文字颜色/;
}
.color{
border-radius:10px;/块圆角值/
box-shadow:0 5px 34px 1px rgba(9,9,88,22);/设置阴影/
color: white;
background-color: cadetblue;
}
.color2{
border-radius:10px;/块圆角值/
margin-left: 20px;/文字距离盒子左侧的距离/
box-shadow:0 5px 34px 1px rgba(9,9,88,22);/设置阴影/
color: white;
background-color: cadetblue;
}
#scjg{
margin-left: 1px;/文字距离盒子左侧的距离/
line-height:30px;/行距/
color:blue;
}
#red{color: red;}
.bdbg{
border-radius:10px;/块圆角值/
box-shadow:0 5px 34px 1px rgba(9,9,88,22);/设置阴影/
color: white;
background-color:darkslategrey;
}
</style>
</head>
<body>
<div id="zm">
<div id="zm2">
<p id="p">
<a align="center">Form表单计算器V1.0</a>
<br>
<form method="get">
<input class="bdbg" type="text" name="zm1">
<select class="bdbg" name="fuhao">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input class="bdbg" type="text" name="zm2">

					&lt;input    class=&#34;color2&#34; type=&#34;submit&#34; value=&#34;计算&#34;&gt;
				&lt;/form&gt;
&lt;/p&gt;

<?php

	if (isset($_post[&#39;zm1&#39;]) &amp;&amp; isset ($_POST[&#39;zm2&#39;])){
	$zm1 = $_POST[&#39;zm1&#39;];
	$zm2 = $_POST[&#39;zm2&#39;];
	$fuhao = $_POST[&#39;fuhao&#39;];
	
	var_dump($_POST);
		echo &#39;&lt;br&gt;&#39;;
		switch($fuhao){
		case &#39;+&#39; : echo $zm1.&#39;+&#39;.$zm2. &#39;=&#39; ,$zm1+$zm2;break;
		case &#39;-&#39; : echo $zm1.&#39;-&#39;.$zm2. &#39;=&#39; ,$zm1-$zm2;break;
		case &#39;*&#39; : echo $zm1.&#39;*&#39;.$zm2. &#39;=&#39; ,$zm1*$zm2;break;
		case &#39;/&#39; : echo $zm1.&#39;/&#39;.$zm2. &#39;=&#39; ,$zm1/$zm2;break;
		default : echo &#39;非法运算符&#39;; break; 
		}
	}
		echo &#39;&lt;b&gt;&lt;a id=&#34;scjg&#34;&gt;计算结果:&lt;/a&gt;&lt;/b&gt;&#39;;
		if (isset($_GET[&#39;zm1&#39;]) &amp;&amp; isset ($_GET[&#39;zm2&#39;])){
	$zm1 = $_GET[&#39;zm1&#39;];
	$zm2 = $_GET[&#39;zm2&#39;];
	$fuhao = $_GET[&#39;fuhao&#39;];

// echo '<br>';
// var_dump($_GET);
echo '<br>';echo '<p></p>';
switch($fuhao){
case '+' : echo zm1.&#39;+&#39;.zm2. '=' ,zm1+zm2;break;
case '-' : echo zm1.&#39;-&#39;.zm2. '=' ,zm1-zm2;break;
case '*' : echo zm1.&#39;*&#39;.zm2. '=' ,zm1*zm2;break;
case '/' : echo zm1.&#39;/&#39;.zm2. '=' ,zm1/zm2;break;
// 优化: 判断空值输出提示,但我还不会判断。
default : echo '非法运算符'; break;
}
}

?>

	&lt;/div&gt;&lt;/div&gt;
	
	
	
&lt;/body&gt;

</html>