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.
Result of php executing
Full code of calculator.php
- <?php
- $operator = readline("Welke operatie wil je uitvoeren? (+, -, %,)" . PHP_EOL);
- $a = readline("Eerste getal? . PHP_EOL");
- if (is_numeric($a)) {
- "";
- } else {
- exit("'" . $a . "' is geen getal" . PHP_EOL);
- }
- $b = readline("Tweede getal? . PHP_EOL");
- echo $b . PHP_EOL;
- if (is_numeric($b)) {
- "";
- } else {
- exit("'" . $b . "' is geen getal" . PHP_EOL);
- }
- if ($operator == ('+')) {
- exit("Uw resultaat is: " . $sum1 = $a + $b . PHP_EOL);
- } elseif ($operator == ('-')) {
- exit("Uw resultaat is: " . $sum2 = $a - $b . PHP_EOL);
- } elseif ($operator == ('%')) {
- exit("Uw resultaat is: " . $sum2 = $a % $b . PHP_EOL);
- } else {
- exit("geen geldige operatie" . PHP_EOL);
- }
- ?>