php+html Implementing a Web page calculator

Source: Internet
Author: User

<!--set the center alignment within the table, the table border 2px-->
<table align= "center" border= "2px" ><tr><td><input type= "text" name= "Number1" size=4></td ><td><select name= "Caculate" size= "1" ><option value= "+" >+</option><option value= "-" >-</option><option value= "*" >*</option><option value= "/" >/</option><option Value= "%" >%</option></select></td><td><input type= "text" name= "Number2" size=4> </td><td><input type= "Submit" Name= "OK" value= "calculation" size=4></td> </tr>

Set the first line (input line)

<TR align= "center" >
<!--colspan is used to merge cells to make the output data centered and more aesthetically pleasing. --><TD width= "full" colspan= "4" ><?phpfunction caculate ($numb 1, $numb 2, $method) {switch ($method) {case ' + ' : Return $numb 1+ $numb 2;break;case '-': return $numb 1-$numb 2;break;case ' * ': return $numb 1* $numb 2;break;case '/': return $ numb1/$numb 2;break;case '% ': return $numb 1% $numb 2;break;default:break;}} if (Isset ($_post[' OK ')) {$numb 1=$_post[' number1 '); $numb 2=$_post[' number2 ']; $method =$_post[' caculate '];if (is_ Numeric ($numb 1) &&is_numeric ($numb 2)) {if ($method = = '/' && $numb 2==0) {echo "<script>alert (' The divisor cannot be "0", please re-enter! </script> "; return;} $res =caculate ($numb 1, $numb 2, $method), echo "$numb 1 $method $numb 2 = $res";} Else{echo "<script>alert (' you entered not a number, please re-enter! ') </script> ";}}? ></td></tr>

Set second row (output line)

1<!doctype html>234<meta charset= "Utf-8" >5<title> Web Computers </title>67<style type= "Text/css" >8 h1{9Font-size=24px;TenText-align:Center; Onefont-family: "Blackbody" ; A     } -      -      the</style> -<body> - -<form method= "POST" > +<table align= "center" border= "2px" > -<tr> +<td> A<input type= "text" name= "Number1" size=4> at</td> -<td> -<select name= "Caculate" size= "1" > -<option value= "+" >+</option> -<option value= "-" >-</option> -<option value= "*" >*</option> in<option value= "/" >/</option> -<option value= "%" >%</option> to</select> +</td> -<td> the<input type= "text" name= "Number2" size=4> *</td> $<td>Panax Notoginseng<input type= "Submit" Name= "OK" value= "calculation" size=4> -</td> the</tr> +&LT;TR align= "center" > A&LT;TD width= "full" colspan= "4" > the<?PHP +                     functionCaculate ($numb 1,$numb 2,$method) -                     { $                         Switch($method) $                         { -                              Case' + ': -                                 return $numb 1+$numb 2; the                                  Break; -                              Case‘-‘:Wuyi                                 return $numb 1-$numb 2; the                                  Break; -                              Case‘*‘: Wu                                 return $numb 1*$numb 2; -                                  Break; About                              Case‘/‘: $                                 return $numb 1/$numb 2; -                                  Break; -                              Case‘%‘: -                                 return $numb 1%$numb 2; A                                  Break; +                             default: the                                  Break; -                         } $                     } the                     if(isset($_post[' OK '])) the                     { the                         $numb 1=$_post[' Number1 ']; the                         $numb 2=$_post[' Number2 ']; -                         $method=$_post[' Caculate ']; in                         if(Is_numeric($numb 1) &&Is_numeric($numb 2)) the                         { the                             if($method= = '/' &&$numb 2==0) About                             { the                                 Echo"<script>alert (' divisor cannot be" 0 ", please re-enter!) ') </script> "; the                                 return; the                             } +                             $res=caculate ($numb 1,$numb 2,$method); -                             Echo"$numb 1 $method $numb 2=$res"; the                         }Bayi                         Else the                         { the                             Echo"<script>alert (' you entered not a number, please re-enter!") ') </script> "; -                         } -                     } the?> the</td> the</tr> the</table> -</form> the      the</body> the

Full code

php+html Implementing a Web page calculator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.