E2_Rechner - 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 E2_Rechner.php

  1. <!DOCTYPE html>
  2. <html lang="de">
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Einsende 2 Rechner</title>
  6.   </head>
  7. <body>
  8.           <?php 
  9. function addiere($summand1, $summand2) {
  10.         return ($summand1 + $summand2); 
  11. }
  12.  
  13. function subtrahiere($minuend, $subtrahend) {
  14.         return ($minuend - $subtrahend); 
  15. }
  16.   
  17. function multipliziere($faktor1, $faktor2) {
  18.         return ($faktor1 * $faktor2); 
  19. }
  20.   
  21. function dividiere($dividend, $divisor) {
  22.         if ($divisor != 0) { 
  23.                 return ($dividend / $divisor); 
  24.         }
  25. } 
  26. ?>
  27.     
  28. <form action= "<?php echo $_SERVER["PHP_SELF"];?>" method = "post"> 
  29.     
  30. <?php
  31.     
  32.     if (isset ( $_POST ["zahl1"])) {
  33.            $zahl1 = $_POST ["zahl1"];
  34.            $zahl2 = $_POST ["zahl2"];
  35.            $ergebnis =addiere ($zahl1, $zahl2);
  36.     echo"<h3>die Summe der Addition
  37.         $zahl1 + $zahl2 beträgt
  38.         $ergebnis!</h3>\n";
  39.     }
  40.     
  41.     if (isset ( $_POST ["zahl1"])) {
  42.         $zahl1 = $_POST ["zahl1"];
  43.            $zahl2 = $_POST ["zahl2"];
  44.            $ergebnis =subtrahiere ($zahl1, $zahl2);
  45.     echo"<h3>die Summe der Subtraktion
  46.         $zahl1 - $zahl2 beträgt
  47.         $ergebnis!</h3>\n";           
  48.     }
  49.     
  50.     if (isset ( $_POST ["zahl1"])) {
  51.            $zahl1 = $_POST ["zahl1"];
  52.            $zahl2 = $_POST ["zahl2"];
  53.            $ergebnis =multipliziere ($zahl1, $zahl2);
  54.     echo"<h3>die Summe der Multiplikation
  55.         $zahl1 * $zahl2 beträgt
  56.         $ergebnis!</h3>\n";
  57.     }
  58.     
  59.     if (isset ( $_POST ["zahl1"])) {
  60.            $zahl1 = $_POST ["zahl1"];
  61.            $zahl2 = $_POST ["zahl2"];
  62.            $ergebnis =dividiere ($zahl1, $zahl2);
  63.     echo"<h3>die Summe der Division
  64.         $zahl1 / $zahl2 beträgt
  65.         $ergebnis!</h3>\n";
  66.     }
  67. ?>
  68.         
  69.         
  70.     <h3> Bitte geben Sie die beiden Zahlen in die Felder ein.</h3>
  71.         <input type="text" 
  72.            name ="zahl1"
  73.            required
  74.     placeholder="Bitte Zahl eingeben"
  75.             autofocus/>
  76.         
  77.     <p>
  78.    <input type="text" 
  79.            name ="zahl2"
  80.            required
  81.     placeholder="Bitte Zahl eingeben"
  82.             autofocus/>
  83.       </p>
  84.     <p>
  85. <input type="radio" name="operation" value="+">+<br>
  86. <input type="radio" name="operation" value="-">-<br>
  87. <input type="radio" name="operation" value="*">*<br>
  88. <input type="radio" name="operation" value="/">/<br>
  89. </p>
  90.          
  91.         <input type="submit" value="Rechnen" input>
  92.       </form>  
  93.  
  94.     </body>
  95.  </html
File Description
  • E2_Rechner
  • PHP Code
  • 25 Sep-2020
  • 2.25 Kb
You can Share it: