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

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.         <meta charset="utf-8">
  5.         <meta name="viewport" content="widht=device-widht, initial-scale=1.0">
  6.         <title>The green dress</title>
  7. </head>
  8. <body style="background-color: #73F182">
  9.         <form action="" method="post">
  10.                 <h2 style="text-align: center; color: #10A749"> Welcome to the green color center !</h2>
  11.                 <p style=" color: #10A749">Enter the code you want to check : </p>
  12.                
  13.                 <input type="text" name="code" id="code" style="color : #10A749">
  14.                 <input type="submit" name="submit" value="Check" style="color:#10A749">
  15.  
  16.  
  17.  
  18.  
  19.  
  20.         </form>
  21.  
  22. </body>
  23. </html>
  24.  
  25. <?php 
  26.     $matching_indexes = [];
  27.     $input = "E3F5B7, 600B4A, 9DB75A, 44AFA7, E065C0, 37665B, 89B0F8, 37210D";
  28.     $colors = explode(',', $input);
  29.     var_dump($colors);
  30.     $colors = str_replace(' ', '', $colors);
  31.     var_dump($colors);
  32.     foreach($colors as $index => $color) {
  33.         if (strlen($color) === 6) {
  34.             $red = hexdec(substr($color, 0, 2));
  35.             $green = hexdec(substr($color, 2, 2));
  36.             $blue = hexdec(substr($color, -2));
  37.             if ($green > $red && $green > $blue) {
  38.                 $matching_indexes[] = $index;
  39.             }  
  40.         }
  41.     }
  42.     
  43.     var_dump($matching_indexes);
  44.  
  45.  
  46. ?>
File Description
  • zad3
  • PHP Code
  • 15 Jan-2021
  • 1.24 Kb
You can Share it: