changer - 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 changer.php
- <!DOCTYPE html>
- <html>
- <head>
- <title>Studi Kasus</title>
- <style>
- body{
- text-align: center;
- background-color: ghostwhite;
- }
- h1{
- text-align: center;
- }
- th{
- background-color: aqua;
- border: 1px dashed black;
- }
- table{
- border: 1px dashed black;
- }
- td{
- border-right: 1px solid black;
- background-color: ghostwhite;
- }
- p{
- font-family: cursive;
- }
- button{
- transition: .3s;
- background-color: aqua;
- font-family: cursive;
- border: 1px solid black
- }
- button:hover{
- transition: .3s;
- border-radius: 5px;
- font-weight: bold;
- }
- select{
- border-radius: 5px;
- font-weight: bold;
- background-color: aqua;
- transition: .3s;
- }
- input{
- border-radius: 5px;
- border: 1px solid black;
- padding: 3px;
- }
- </style>
- </head>
- <body>
- <h1>
- Money Changer</h1>
- <table border="0" align="center" cellspacing="1" cellpadding="5">
- <tr>
- <th>Mata uang asing</th>
- <th>Mata uang indonesia</th>
- </tr>
- <tr>
- <td>Dollar amerika</td>
- <td>12000</td>
- </tr>
- <tr>
- <td>Dollar singapura</td>
- <td>7000</td>
- </tr>
- <tr>
- <td>Yen</td>
- <td>4000</td>
- </tr>
- <tr>
- <td>Won</td>
- <td>11</td>
- </tr>
- </table>
- <h1>
- Transaksi</h1>
- <form action="" method="post">
- Masukkan nominal anda : <input placeholder="Input Your Nominal" type="text" name="uang">
- <select name="mataUang">
- <option value="12000">Dollar Amerika</option>
- <option value="7000">Dollar Singapura</option>
- <option value="4000">Yen</option>
- <option value="11">Won</option>
- </select>
- <button type="submit">Konversi</button>
- </form>
- <?php
- $uang = (int)$_POST['uang'];
- $mataUang = (int)$_POST['mataUang'];
- $tipe = $mataUang == 12000 ? "Dollar Amerika" : ($mataUang == 7000 ? "Dollar Singapura" : ($mataUang == 4000 ? "Yen" : "Won"));
- echo "<p>
- " . kembali($uang,$mataUang) . " " . $tipe . "</p>
- ";
- function kembali($uang,$mataUang){
- return $uang / $mataUang ;
- }
- ?>
- </body>
- </html>