<?php
@session_start();
//归零处理
if($_POST[stop] != "")
{$_SESSION=array();}
//定义四种算法
$_SESSION[plus]=trim($_POST[plus]);
$_SESSION[minus]=trim($_POST[minus]);
$_SESSION[divide]=trim($_POST[divide]);
$_SESSION[X]=trim($_POST[X]);
//定义数字
$a0=trim($_POST[a0]);
$a1=trim($_POST[a1]);
$a2=trim($_POST[a2]);
$a3=trim($_POST[a3]);
$a4=trim($_POST[a4]);
$a5=trim($_POST[a5]);
$a6=trim($_POST[a6]);
$a7=trim($_POST[a7]);
$a8=trim($_POST[a8]);
$a9=trim($_POST[a9]);
$aa=trim($_POST[aa]);
//判断现实当前运算数
if($a0=="0"){$_SESSION[pbs]=$_SESSION[pbs].$a0;}
elseif($a1=="1"){$_SESSION[pbs]=$_SESSION[pbs].$a1;}
elseif($a2=="2"){$_SESSION[pbs]=$_SESSION[pbs].$a2;}
elseif($a3=="3"){$_SESSION[pbs]=$_SESSION[pbs].$a3;}
elseif($a4=="4"){$_SESSION[pbs]=$_SESSION[pbs].$a4;}
elseif($a5=="5"){$_SESSION[pbs]=$_SESSION[pbs].$a5;}
elseif($a6=="6"){$_SESSION[pbs]=$_SESSION[pbs].$a6;}
elseif($a7=="7"){$_SESSION[pbs]=$_SESSION[pbs].$a7;}
elseif($a8=="8"){$_SESSION[pbs]=$_SESSION[pbs].$a8;}
elseif($a9=="9"){$_SESSION[pbs]=$_SESSION[pbs].$a9;}
elseif($aa=="."){$_SESSION[pbs]=$_SESSION[pbs].$aa;}
//运算符
if($_SESSION[plus]=="+")
  {$_SESSION[pbs1]=$_SESSION[pbs];
  $_SESSION[pbs]="";
  $_SESSION[yun]="+";}
elseif($_SESSION[minus]=="-")
  {$_SESSION[pbs1]=$_SESSION[pbs];
  $_SESSION[pbs]="";
  $_SESSION[yun]="-";}
elseif($_SESSION[X]=="*")
  {$_SESSION[pbs1]=$_SESSION[pbs];
  $_SESSION[pbs]="";
  $_SESSION[yun]="*";}
elseif($_SESSION[divide]=="/")
  {$_SESSION[pbs1]=$_SESSION[pbs];
  $_SESSION[pbs]="";
  $_SESSION[yun]="/";}
//运算
if($_POST[begin] != "")
{
if($_SESSION[yun]=="+")
{$_SESSION[pbs]=$_SESSION[pbs1] + $_SESSION[pbs];
  $_SESSION[pbs1]=$_SESSION[pbs];}
elseif($_SESSION[yun]=="-")
{$_SESSION[pbs]=$_SESSION[pbs1] - $_SESSION[pbs];}
elseif($_SESSION[yun]=="*")
{$_SESSION[pbs]=$_SESSION[pbs1] * $_SESSION[pbs];}
elseif($_SESSION[yun]=="/")
{$_SESSION[pbs]=$_SESSION[pbs1] / $_SESSION[pbs];}

}


 ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="robots" content="noindex,nofllow">
<title>PHP计算器</title>
<style type="text/css">
<!--
.STYLE1 {
color: #0033FF;
font-family: "新宋体";
}
-->
</style>
</head>
<body bgcolor="#0099bb">
<center>
<form id="form1" name="form1" method="post" action="info.php">
<table width="183" height="161" border="0">
  
    <td height="25" colspan="3"><div align="right" style="background:#fff">
      
     <?php
  if($_SERVER[pbs] < 0) echo "-";
  if($_SESSION[pbs]!=""){echo $_SESSION[pbs];}else{echo "0";}
   ?>
     
      
      
      </div></td>
    
    <td  colspan="2"><input name="stop" type="submit" id="button9" value="归零" /> </td>
    </tr>
  <tr>
    <td width="37" height="25">
      <input type="submit" name="a7" id="button6" value=" 7 " />    </td>
    <td width="37">
      <input type="submit" name="a8" id="button7" value=" 8 " />    </td>
    <td width="37">
      <input type="submit" name="a9" id="button8" value=" 9 " />    </td>
    <td width="1" rowspan="6"> </td>
    <td><input type="submit" name="plus" id="button11" value=" + " /></td>
    </tr>
  <tr>
    <td height="25"><input type="submit" name="a4" id="button3" value=" 4 " /></td>
    <td><input type="submit" name="a5" id="button4" value=" 5 " /></td>
    <td>
      <input type="submit" name="a6" id="button5" value=" 6 " />    </td>
    <td><input type="submit" name="minus" id="button12" value=" - " /></td>
    </tr>
  <tr>
    <td height="25">
      
        <input type="submit" name="a1" id="button" value=" 1 " />        </td>
    <td>
      <input type="submit" name="a2" id="botton" value=" 2 " />    </td>
    <td><input type="submit" name="a3" id="button2" value=" 3 " /></td>
    <td>
      <input type="submit" name="divide" id="button15" value=" / " />    </td>
    </tr>
  <tr>
    <td height="25">
      <input type="submit" name="a0" id="button10" value=" 0 " />    </td>
    <td>
      <input type="submit" name="aa" id="button16" value=" . " />    </td>
    <td><input type="submit" name="begin" id="button13" value=" = " /> </td>
    <td>
      <input type="submit" name="X" id="button14" value=" * " />    </td>
    </tr>
</table>
</form>
</center>
</body>
</html>