SEARCH
Newsletter
Subscribe to get design
tips, latest trends, free
stuff and more.
It doesn't look like an e-mail address

hosting

  Web Programming PHP Php calculator

Php calculator

Cable PHP Nov 14, 2006

PHP CalculatorThis tutorial will teach you how to make a calculator using PHP.

Firstly, create a new .php document and copy/paste the following code into it.

<?php

/* Calculator */


if($submit)
{
   if($operator == '*')
   {
       echo $numa * $numb;
   } elseif($operator == '/')
   {
       echo $numa / $numb;
   } elseif($operator == '+')
   {
       echo $numa + $numb;
   } elseif($operator == '-')
   {
       echo $numa - $numb;
   }
} else { ?>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
 <input type="text" name="numa" size="10">
 <input type="text" name="operator" size="2">
 <input type="text" name="numb" size="10">
 <input type="submit" value="Calculate" name="submit">
</form>
<?php } ?>

Legend:

* Multiply
- Subtract
/ Divide
+ Add

   
subscribe to newsletter