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. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 722 Bytes
You can Share it: