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. $getal_1 = readline("Eerste getal?" . PHP_EOL);
  4. $getal_2 = readline("Tweede getal?" . PHP_EOL);
  5.  
  6. if (!is_numeric($getal_1)) { 
  7.     exit("Het eerste getal was ongeldig!");
  8. } else if (!is_numeric($getal_2)) { 
  9.     exit("Het tweede getal is ongeldig!");
  10. } 
  11.  
  12. $var1 = '$getal_1'; 
  13. echo("Variable: ".$var);
  14. echo"\nAfter the intval() function...";
  15. $int_val= intval($var); 
  16. echo "\nInteger value: ".$int_val2; 
  17.  
  18. $var2 = '$getal_2'; 
  19. echo("Variable: ".$var);
  20. echo"\nAfter the intval() function...";
  21. $int_val= intval($var); 
  22. echo "\nInteger value: ".$int_val2; 
  23.  
  24.  
  25. $operator = readline('Welke operatie wil je uitvoeren? (+, -, %) ' . PHP_EOL);
  26.  
  27. if ($operator === ("+")) {
  28.         $sum1 = $getal_1 + $getal_2;
  29.         echo "Uw resultaat is: " . $sum1;
  30. } else if ($operator === ("-")) {
  31.         $sum2 = $getal_1 - $getal_2;
  32.         echo "Uw resultaat is: " . $sum2;
  33. } else if ($operator === ("%")) {
  34.         $sum3 = $getal_1 % $getal_2;
  35.         echo "Uw resultaat is: " . $sum3;
  36. } 
  37. ?>
File Description
  • calculator
  • PHP Code
  • 12 Sep-2021
  • 978 Bytes
You can Share it: