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. $operation = readline(“Welke operatie wil je uitvoeren? (+, -, %));
  2. $op1 = "+";
  3. $op2 = "-";
  4. $op3 = "%";
  5.  
  6. if ($operation == $op1) {
  7.     echo (“Optellen”) . PHP_EOL;
  8. } elseif ($operation == $op2) {
  9.     echo (“Aftrekken”) . PHP_EOL;
  10. } elseif ($operation == $op3) {
  11.     echo (%) . PHP_EOL;
  12. } else {
  13.     exit(“geen geldige operatie” . PHP_EOL);
  14. }
  15.  
  16. $a = readline(“Je eerste getal?” . PHP_EOL);
  17. if (!is_numeric($a)){
  18. } else { 
  19.     exit(“‘” . $a . “’ is geen getal” . PHP_EOL);
  20. }
  21. $b = readline(“Je tweede getal?” . PHP_EOL);
  22. if (!is_numeric($b)){
  23. } else { 
  24.     exit(“‘” . $b . “’ is geen getal” . PHP_EOL);
  25. }
  26. if ($operation == $op1) {
  27.     $sum1 = $a + $b;
  28.     echo (“Het resultaat is: ” . $sum1) . PHP_EOL;
  29. } elseif ($operation == $op2) {
  30.     $sum2 = $a - $b;
  31.     echo (“Het resultaat is: ” . $sum2) . PHP_EOL;
  32. } elseif ($operation == $op3) {
  33.     $sum3 = $a % $b;
  34.     echo (“Het resultaat is: ” . $sum3) . PHP_EOL;
  35. }
  36. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 978 Bytes
You can Share it: