Beispiel #1
0
{
    if ($objectHasJuice == true) {
        return true;
    } else {
        return false;
    }
}
function isRed($objectColor)
{
    if ($objectColor == "red") {
        return true;
    } else {
        return false;
    }
}
if (isValidInput()) {
    $objectName = $_GET["name"];
    if (isApple($objectName)) {
        if (isJuicy($objectHasJuice)) {
            if (isRed($objectColor)) {
                echo "Mmmmm... This is a red juicy apple!";
            } else {
                echo "Gross... This isn't a red juicy apple!";
            }
        } else {
            echo "Gross... This isn't a red juicy apple!";
        }
    } else {
        echo "Gross... This isn't a red juicy apple!";
    }
} else {
Beispiel #2
0
		<br>converter
	</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));