By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
LahbabiGuideLahbabiGuide
  • الرئيسية
  • مزيج مِن أفكاري
    • مقالاتي
    • قصص قصيرة
    • سيناريوهات أفلام قصيرة
    • نصوص مسرحية قصيرة
  • أفكار المشاريع
  • قصص النجاح
  • أخبار تقنية
  • القرأن الكريم
Search
  • Advertise
© 2022 Zakariaelahbabi.com . Company. All Rights Reserved.
Reading: PHP Calculator Example With Source Code | Basic Calculator in PHP
Share
Notification Show More
Latest News
bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap
php-age-calculator-program-|-calculate-age-in-php
PHP Age Calculator Program | Calculate Age In PHP
PHP
Aa
LahbabiGuideLahbabiGuide
Aa
  • مزيج مِن أفكاري
  • أخبار تقنية
  • تطوير الويب
  • أفكار المشاريع
Search
  • Home
    • Home 1
    • Default Home 2
    • Default Home 3
    • Default Home 4
    • Default Home 5
  • Categories
    • تطوير الويب
    • أخبار تقنية
    • أفكار المشاريع
    • مزيج مِن أفكاري
    • قصص النجاح
  • Bookmarks
  • More Foxiz
    • Sitemap
Follow US
  • Advertise
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
php-calculator-example-with-source-code-|-basic-calculator-in-php
LahbabiGuide > تطوير الويب > PHP > PHP Calculator Example With Source Code | Basic Calculator in PHP
PHP

PHP Calculator Example With Source Code | Basic Calculator in PHP

admin
Last updated: 2023/03/11 at 7:37 صباحًا
By admin
Share
4 Min Read
SHARE

How can we create a PHP Calculator? By very less coding & following some steps, we can create a basic calculator in PHP. This tutorial is for those people who want to learn PHP & beginner in PHP. If you have good knowledge in PHP you can create this program in less then 10 minutes.

Contents
Preview of Calculator ProgramSource Code Of Simple PHP Calculator Program.{$_POST[‘number1’]} {$_POST[‘operation’]} {$_POST[‘number2’]} equals {$total}

Previously I had shared how to make a calculator with JavaScript? Now at this time, I am sharing the same type of calculator in the PHP platform. Basically, I created this program in PHP If { } statement. The If { } statement of any programming language work like either-or. Know more about PHP If statement. 

I create this program in PHP & Bootstrap. I used bootstrap because I am lazy little bit, Using bootstrap I saved my almost 2-3 minute. First, I had created a form with method="POST" then I added action with the same name of the program file. I had saved this program named calculator.php So, I had placed action="calculator.php" in the form tag. Example:

Then I had created two text input and one option menu using HTML or Bootstrap. Gave the first input name ‘number1‘ and for the second input ‘number2‘. Example: & gave name for selection section. Example:

Preview of Calculator Program

Let’s see a preview of this calculator in GIF version. In other words, see how this calculator works.

php calculator preview

You May Also Like:

  • Login System in PHP
  • Domain Availability Checker In PHP
  • Simple Quiz In PHP

Source Code Of Simple PHP Calculator Program.

Now here I am sharing the source code of this basic PHP calculator, Who was still talking about. This is a very small program So, I created just one file for this. I am sure you will fully understand the whole program just looking at source code. Because this code is so simple & clean.

Create a file name ‘calculator.php‘ and put these following code given here below. Just Copy & Paste.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

<!DOCTYPE html>

<!— code by webdevtrick ( https://webdevtrick.com) –>

<html>

<head>

<title>Simple Calculator In PHP | Webdevtrick.com</title>

<meta charset=“utf-8”>

<meta http–equiv=“X-UA-Compatible” content=“IE=edge”>

<meta name=“viewport” content=“width=device-width, initial-scale=1”>

<link href=“https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css” rel=“stylesheet”>

</head>

<body>

<div class=“container” style=“margin-top: 50px”>

// If the submit button has been pressed

if(isset($_POST[‘submit’]))

{

// Check number values

if(is_numeric($_POST[‘number1’]) && is_numeric($_POST[‘number2’]))

{

// Calculate total

if($_POST[‘operation’] == ‘plus’)

{

$total = $_POST[‘number1’] + $_POST[‘number2’];

}

if($_POST[‘operation’] == ‘minus’)

{

$total = $_POST[‘number1’] – $_POST[‘number2’];

}

if($_POST[‘operation’] == ‘multiply’)

{

$total = $_POST[‘number1’] * $_POST[‘number2’];

}

if($_POST[‘operation’] == ‘divided by’)

{

$total = $_POST[‘number1’] / $_POST[‘number2’];

}

// Print total to the browser

echo “

{$_POST[‘number1’]} {$_POST[‘operation’]} {$_POST[‘number2’]} equals {$total}

“;

} else {

// Print error message to the browser

echo ‘Numeric values are required’;

}

}

// end PHP. Code by webdevtrick.com

?>

    <!— Calculator form by webdevtrick.com —>

    <form method=“post” action=“calculator.php”>

        <input name=“number1” type=“text” class=“form-control” style=“width: 150px; display: inline” />

        <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>

        <input name=“number2” type=“text” class=“form-control” style=“width: 150px; display: inline” />

        <input name=“submit” type=“submit” value=“Calculate” class=“btn btn-primary” />

    </form>

</div>

</body>

</html>

Now you have successfully created this program. now time to understand this program, look at the code you will definitely understand. I also placed a comment on every section of codes. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

You Might Also Like

Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit

Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table

Upload Image In PHP With MySQL Database | Web Dev Trick

PHP Age Calculator Program | Calculate Age In PHP

Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip

TAGGED: basic php calculator, Bootstrap, calculator program, PHP, php source code, php tutorial, source code, Web Development
admin مارس 11, 2023
Share this Article
Facebook Twitter Pinterest Whatsapp Whatsapp LinkedIn Tumblr Reddit VKontakte Telegram Email Copy Link Print
Previous Article crud-php-mysql-example-and-source-code-|-with-ajax-no-reloading CRUD PHP MySQL Example and Source Code | With Ajax No Reloading
Next Article php-shopping-cart-|-add-to-cart-feature-in-php-&-mysql PHP Shopping Cart | Add to Cart Feature In PHP & MySQL
Leave a comment Leave a comment

اترك تعليقاً إلغاء الرد

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *

Stay Connected

235.3k Followers Like
69.1k Followers Follow
11.6k Followers Pin
56.4k Followers Follow
136k Subscribers Subscribe
4.4k Followers Follow
- Advertisement -
Ad imageAd image

Latest News

bootstrap-clean-buttons-with-hover-effect-|-plain-button-ui-kit
Bootstrap Clean Buttons With Hover Effect | Plain Button UI Kit
Bootstrap مارس 11, 2023
bootstrap-datatable-with-sort,-pagination,-and-search-|-sorting-data-table
Bootstrap Datatable With Sort, Pagination, and Search | Sorting Data Table
Bootstrap مارس 11, 2023
upload-image-in-php-with-mysql-database-|-web-dev-trick
Upload Image In PHP With MySQL Database | Web Dev Trick
PHP مارس 11, 2023
bootstrap-tooltip-progress-bar-animation-|-percentage-values-in-tooltip
Bootstrap Tooltip Progress Bar Animation | Percentage Values in Tooltip
Bootstrap مارس 11, 2023
//

We influence 20 million users and is the number one business and technology news network on the planet

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

[mc4wp_form id=”847″]

LahbabiGuideLahbabiGuide
Follow US

© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.

Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc..

[mc4wp_form]
Zero spam, Unsubscribe at any time.

Removed from reading list

Undo
Welcome Back!

Sign in to your account

Lost your password?