<?php $text = $_GET['text']; $red = getHex($_GET['red']); $green = getHex($_GET['green']); $blue = getHex($_GET['blue']); $color = '#' . $red . $green . $blue; $nth = $_GET['nth']; var_dump($color); var_dump('738f0d'); echo "<p>"; for ($i = 1; $i <= strlen($text); $i++) { if ($i % $nth === 0) { echo "<span style=\"color: {$color}\">" . htmlspecialchars($text[$i - 1]) . "</span>"; } else { echo htmlspecialchars($text[$i - 1]); } } echo "</p>"; function getHex($color) { $color = dechex($color); var_dump($color); if (strlen($color) === 1) { $color .= $color; } return $color; }
</h2> </header> <form method="POST"> <label for="red">Red: </label> <input name="red" id="red" type="text" class="rgb-input" maxlength="3"> <label for="green">Green: </label> <input name="green" id="green" type="text" class="rgb-input" maxlength="3"> <label for="blue">Blue: </label> <input name="blue" id="blue" type="text" class="rgb-input" maxlength="3"> <input type="submit" name="submit" value="Convert to Hex" class="convert-btn"> </form> <div class="result"> <?php if (isset($_POST["red"]) && isset($_POST["green"]) && isset($_POST["blue"])) { if (isValidInput($_POST["red"]) && isValidInput($_POST["green"]) && isValidInput($_POST["blue"])) { echo "#" . getHex($_POST["red"]) . getHex($_POST["green"]) . getHex($_POST["blue"]); } else { echo "Please enter valid input:<br>RGB values should be from 0 to 255 only!"; } } function isValidInput($rgb) { if (!is_numeric($rgb)) { return false; } return $rgb >= 0 && $rgb <= 255; } function getHex($rgb) { $result = strtoupper(dechex($rgb)); if (strlen($result) == 1) {