Use php to implement addition, subtraction, multiplication, division, and calculator. The code is simple!
Copy codeThe Code is as follows:
<? Php
Header ("content-type: text/html; charset = UTF-8 ");
Session_start ();
?>
<! 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" xml: lang = "zh-CN" dir = "ltr">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> simple computer </title>
</Head>
<Body>
<Form action = "jisuan. php" method = "post">
Number 1 <input type = "text" value = "" name = "num1"> <br/>
Symbol <select name = "symbol">
<Option value = "+" >+ </option>
<Option value = "-">-</option>
<Option value = "*"> * </option>
<Option value = "/">/</option>
</Select> <br/>
Number 2 <input type = "text" value = "" name = "num2"> <br/>
<Input type = "submit" value = "calculation result"> <br/>
</Form>
</Body>
</Html>
<? Php
$ Num1 = $ _ POST ['num1'];
$ Num2 = $ _ POST ['num2'];
$ Scheme = $ _ POST ['signature'];
$ Rs = 0;
Switch ($ Scheme ){
Case "+ ":
$ Rs = $ num1 + $ num2;
Break;
Case "-":
$ Rs = $ num1-$ num2;
Break;
Case "*":
$ Rs = $ num1 * $ num2;
Break;
Case "/":
$ Rs = $ num1/$ num2;
Break;
Default: echo "your input is incorrect ";
}
$ _ SESSION ['rs '] = $ rs;
Echo: '. $ _ SESSION ['rs'];
?>