How to Create a Calculator with PHP? | PHP Calculator

Now I’m sharing the source text file of this basic PHP calculator, UN agency was still talking about. this can be a really little program therefore, I created only 1 file for this. I’m positive you may totally perceive the total program simply by observing the source text file. as a result of this code is therefore straightforward & clean.

How to Create a Normal Calculator in PHP?

First, we create the index.php, create an HTML structure in it, then create a form in it, and then we create an input file in it, and then we add CSS to it so that it looks good. Now let’s add PHP coding to it. Let’s do this coding with My programming.

Create a file name ‘index.php‘ and place the subsequent code given here below. simply Copy & Paste.

 <!DOCTYPE html>
<!-- code by Myprograming ( -->
    <title>Simple Calculator In PHP |</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <style type="text/css">
      background: #f3f3f3;
      padding: 50px;
      text-align: center;
      .class1 h1{
        word-wrap: break-word;
    background: #ced2a4;
    padding: 50px 0;
    form .class2{
      padding: 10px;
      border: 1px solid;

    <div class="class1">
           <h1>Simple Calculator In PHP | Create by <a href=""></a></h1>
        <!-- Calculator form by -->
        <form method="post" action="#">
            <input name="num1" type="text" class="class2" style="width: 150px; display: inline" /><br><br>
            <select name="operation">
                <option value="plus">Plus +</option>
                <option value="minus">Minus -</option>
                <option value="multiply">Multiply *</option>
                <option value="divided by">Devide /</option>
            </select> <br><br>
            <input name="num2" type="text" class="class2" style="width: 150px; display: inline" /><br><br>
            <input name="submit" type="submit" value="Calculate" class="class3" />
        // If the submit button has been pressed
          // Check number values
          if(is_numeric($_POST['num1']) && is_numeric($_POST['num2']))
            // Calculate total
            if($_POST['operation'] == 'plus')
              $total = $_POST['num1'] + $_POST['num2']; 
            if($_POST['operation'] == 'minus')
              $total = $_POST['num1'] - $_POST['num2']; 
            if($_POST['operation'] == 'multiply')
              $total = $_POST['num1'] * $_POST['num2']; 
            if($_POST['operation'] == 'divided by')
              $total = $_POST['num1'] / $_POST['num2']; 
            // Print total to the browser
          echo " <script>alert('{$_POST['num1']} {$_POST['operation']} {$_POST['num2']} = {$total}');</script>";
          } else {
            // Print error message to the browser
            echo "<script>alert('Numeric values are required');</script>";
      // end PHP. Code by


Simple Calculator In PHP |

Simple Calculator In PHP | Create by

Screenshot Available How to use

PHP Calculator
Enter Values and Select Opertion

1 thought on “How to Create a Calculator with PHP? | PHP Calculator”

Leave a Comment

Your email address will not be published. Required fields are marked *