<?php
include('includes/header.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Ashlynn's Functions Example</h1>
<form method="POST">
<label for="number">Enter a number for calculation:</label><br>
<input type="number" id="number" name="number" required><br><br>
<label for="text">Enter a text string for manipulation:</label><br>
<input type="text" id="text" name="text" required><br><br>
<input type="submit" value="Submit">
</form>
<?php
function calculateSquare($number) {
return $number * $number;
}
function reverseText($text) {
return strrev($text);
}
function determineBackgroundColor($number) {
return ($number % 2 == 0) ? "plum" : "pink";
}
function formatResults($number, $squaredValue, $reversedText) {
$backgroundColor = determineBackgroundColor($number);
return "<div style='background-color: $backgroundColor; padding: 8px; border-radius: 1px; max-width: 700px;'>" .
"<p>The square of <strong>$number</strong> is <strong>$squaredValue</strong>.</p>" .
"<p>The reversed text is: <strong>$reversedText</strong>.</p></div>";
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$inputNumber = $_POST['number'];
$inputText = $_POST['text'];
$squaredValue = calculateSquare($inputNumber);
$reversedText = reverseText($inputText);
$results = formatResults($inputNumber, $squaredValue, $reversedText);
echo "<h2>Results:</h2>";
echo $results;
}
?>
<?php
echo("<br><br>");
include('includes/footer.php');
?>
</body>
</html>