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.  
  3. $operator = readline("Welke operatie wil je uitvoeren? (+, -, %,)" . PHP_EOL);
  4.  
  5. $a = readline("Eerste getal? . PHP_EOL");
  6.  
  7. if (is_numeric($a)) {
  8.     "";
  9. } else { 
  10.     exit("'" . $a . "' is geen getal" . PHP_EOL);
  11. }
  12.  
  13. $b = readline("Tweede getal? . PHP_EOL");
  14.    echo $b . PHP_EOL;
  15. if (is_numeric($b)) {
  16.     "";
  17. } else { 
  18.     exit("'" . $b . "' is geen getal" . PHP_EOL);
  19. }
  20.  
  21. if ($operator == ('+')) {
  22.     exit("Uw resultaat is: " . $sum1 = $a + $b . PHP_EOL);
  23. } elseif ($operator == ('-')) {
  24.     exit("Uw resultaat is: " . $sum2 = $a - $b . PHP_EOL);
  25. } elseif ($operator == ('%')) {
  26.     exit("Uw resultaat is: " . $sum2 = $a - $b . PHP_EOL);
  27. } else {
  28.     exit("geen geldige operatie" . PHP_EOL);
  29. } 
  30. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 706 Bytes
You can Share it: