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

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  <title>Studi Kasus While</title>
  5.  <style type="text/css">
  6.   body{
  7.    background-color: #f2665c;
  8.    font-family: cursive;
  9.   }
  10.   button{
  11.    background-color: red;
  12.    color: white;
  13.    border: 1px solid black;
  14.   }
  15.  </style>
  16. </head>
  17. <body>
  18.  <h1>
  19. Hitung jumlah huruf</h1>
  20. <br>
  21.  <form method="POST" action="">
  22.   <table>
  23. <tr>
  24.     <td>Masukkan Kalimat</td>
  25.     <td><input type="text" name="nama"></td>
  26.     <td><input type="radio" name="vokal" value="a">a</td>
  27.     <td><input type="radio" name="vokal" value="i">i</td>
  28.     <td><input type="radio" name="vokal" value="u">u</td>
  29.     <td><input type="radio" name="vokal" value="e">e</td>
  30.     <td><input type="radio" name="vokal" value="o">o</td>
  31.     <td><button type="submit">Hitung</button></td>
  32.    </tr>
  33. </table>
  34. </form>
  35. <?php 
  36.   $vokal = $_POST['vokal'];
  37.   $nama = $_POST['nama'];
  38.   $i = 0;
  39.   $jmlvokal = 0;
  40.   
  41.   while ($i < strlen($nama)) {
  42.    if ($nama[$i] == $vokal) {
  43.     $jmlvokal++;
  44.    }
  45.    $i++;
  46.   }
  47.   echo <<<eee
  48.   Jumlah $vokal di <b>$nama</b> adalah $jmlvokal
  49. eee;;
  50.   ?>
  51. </body>
  52. </html>
File Description
  • while
  • PHP Code
  • 29 Oct-2019
  • 1.09 Kb
You can Share it: