calculator - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of calculator.php

  1. <?php
  2. $operator = readline("Welke operatie wil je uitvoeren (+ , - , %)?" . PHP_EOL);
  3. $op1 = "+";
  4. $op2 = "-";
  5. $op3 = "%";
  6.  
  7. $getal_1 = readline("Eerste getal?" . PHP_EOL);
  8. $getal_2 = readline("Tweede getal?" . PHP_EOL);
  9.  
  10. if ($operator === $op1) { 
  11.     echo "De som van " . $getal_1 . " en "
  12.     . $getal_2 . " is " . ($getal_1 + $getal_2); 
  13. } else if ($operator === $op2) { 
  14.     echo "De deviatie van " . $getal_1 . " en "
  15.     . $getal_2 . " is " . ($getal_1 - $getal_2); 
  16. } else {
  17.     echo "De deviatie van " . $getal_1 . " en "
  18.     . $getal_2 . " is " . ($getal_1 - $getal_2); 
  19. }
  20.  
  21. if (!is_numeric($getal_1)) { 
  22.     exit("/geen (getal|nummer)/);
  23. } else if (!is_numeric($getal_2)) { 
  24.     exit("/geen (getal|nummer)/);
  25. } 
  26.  
  27. $var1 = '$getal_1'; 
  28. echo("Variable: " . $var);
  29. echo"\nAfter the intval() function...";
  30. $int_val = intval($var); 
  31. echo "\nInteger value: " . $int_val2; 
  32.  
  33.  
  34. $var2 = '$getal_2'; 
  35. echo("Variable: " . $var);
  36. echo"\nAfter the intval() function...";
  37. $int_val = intval($var); 
  38. echo "\nInteger value: " . $int_val2; 
  39.  
  40. if ($operator === ("+")) {
  41.         $sum1 = $getal_1 + $getal_2;
  42.         echo "Uw resultaat is: " . $sum1;
  43. } else if ($operator === ("-")) {
  44.         $sum2 = $getal_1 - $getal_2;
  45.         echo "Uw resultaat is: " . $sum2;
  46. } else if ($operator === ("%")) {
  47.         $sum3 = $getal_1 % $getal_2;
  48.         echo "Uw resultaat is: " . $sum3;
  49. } 
  50. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 1.33 Kb
You can Share it: