Less familiar JavaScript drip, slowly moving forward, with simple complication of PHP small calculator a copy

Source: Internet
Author: User

interface.php

123<meta charset= "Utf-8"/>4<title> This is a simple calculator </title>56<body>789<form action= "operation.php" method= "POST" Name= "interface" >Ten<table> One<tr><td> Please enter the first number: </td><td><input type= "text" name= "NUM1" value= "/></td></ Tr> A<tr><td> Select the operation symbol:</td> -<td><select name= "Symbol" > -<option value= "+" >+</option> the<option value= "-" >-</option> -<option value= "*" >*</option> -<option value= "/" >/</option> -</select> +</td> -</tr> +<tr><td> Please enter a second number: </td><td><input type= "text" name= "num2" value= "/></td></ Tr> A<tr> at<td><input type= "Submit" value= "Calculation results"/></td> -</tr> -</table> -</form> -<?PHP -     //Empty to determine if the accepted value is null isset to determine if the accepted value exists in     if(isset($_get[' errno '])){ -         $erro=$_get[' errno ']; to         if($erro==1){ +             Echo"<br><font size= ' 4 ' color= ' red ' > input is not a number or is empty, please re-enter! </font> "; -         }    the     } *     //determine if an integer variable exists $     if(isset($_get[' Sum '])){Panax Notoginseng         $sum=$_get[' Sum ']; -         Echo"<br><font size= ' 3 ' color= ' red ' > Operation result is".$sum." </font> "; the     } +     //determine if a number exists A     if(isset($_get[' Dividend '])){ the         $dividend=0; +         Echo"<br><font size= ' 3 ' color= ' red ' > Dividend cannot be".$dividend." </font> "; -     } $?> $</body> -

operation.php

<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" &GT;&LT;?PHPrequire_once"Operation.class.php"; $num 1=$_post[' Num1 ']; $num 2=$_post[' Num2 ']; $symbol=$_post[' symbol ']; //encapsulate the following operations into an operation class    $oper 1=NewOper (); $sum=$oper 1->operation ($num 1,$num 2,$symbol); Header("location:interface.php?sum=$sum"); ?>

operation.class.php

<?PHP//a class for a calculator operation    require_once"Operation.php";//referencing a file    classoper{functionOperation ($num 1,$num 2,$symbol){            //determine if it is a digital is_numeric            if( (Is_numeric($num 1) &&Is_numeric($num 2)) ){                if($symbol= = ' + '){                    $sum=$num 1+$num 2; }                if($symbol= = '-'){                    $sum=$num 1-$num 2; }                if($symbol= = ' * '){                    $sum=$num 1*$num 2; }                if($symbol= = '/'){                    if($num 2==0){                        Header("location:interface.php?dividend=$num 2"); Exit(); }Else{                        $sum=$num 1/$num 2; }                }                return $sum; }Else{                Header("Location:interface.php?errno=1"); Exit(); }            }        }?>

Interface diagram

Less familiar JavaScript drip, slowly moving forward, with simple complication of PHP small calculator a copy

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.