🌸 Nataliia's String Fun! 🌸
Enter your favorite phrase and see some PHP string magic!
Enter your favorite phrase and see some PHP string magic!
<?php
include("includes/header.php"); // optional if your instructor uses header.php
error_reporting(E_ALL);
date_default_timezone_set("America/Detroit");
?>
<!DOCTYPE html>
<html>
<head>
<title>Nataliia's String Fun</title>
<style>
body {
font-family: 'Comic Sans MS', sans-serif;
background-color: #f7f5ff;
color: #333;
text-align: center;
margin-top: 50px;
}
h1 {
color: #7b5fc8;
}
form {
background-color: #fff;
border-radius: 15px;
display: inline-block;
padding: 20px 40px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
input[type="text"] {
width: 300px;
padding: 8px;
border: 1px solid #ccc;
border-radius: 10px;
}
input[type="submit"] {
margin-top: 10px;
background-color: #a98fe2;
color: white;
border: none;
padding: 10px 20px;
border-radius: 10px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #8e73db;
}
.result-box {
background-color: #fff;
border-radius: 15px;
display: inline-block;
padding: 20px 40px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
text-align: left;
margin-top: 20px;
}
a {
color: #7b5fc8;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>🌸 Nataliia's String Fun! 🌸</h1>
<p>Enter your favorite phrase and see some PHP string magic!</p>
<?php
$step = isset($_POST['step']) ? $_POST['step'] : 0;
$input = isset($_POST['input']) ? trim($_POST['input']) : '';
if ($step == 0) {
?>
<form method="POST">
<label><b>Enter a phrase:</b></label><br><br>
<input type="text" name="input" placeholder="Type something cute..." required>
<input type="hidden" name="step" value="1"><br><br>
<input type="submit" value="Show Magic ✨">
</form>
<?php
} else {
echo("<div class='result-box'>");
echo("<h3>Your original phrase:</h3>");
echo("<p>$input</p>");
echo("<h3>String Operations:</h3>");
echo("<p><b>1.</b> Uppercase: " . strtoupper($input) . "</p>");
echo("<p><b>2.</b> Lowercase: " . strtolower($input) . "</p>");
echo("<p><b>3.</b> Length: " . strlen($input) . " characters</p>");
echo("<p><b>4.</b> Reversed: " . strrev($input) . "</p>");
echo("<p><b>5.</b> First word only: " . strtok($input, ' ') . "</p>");
echo("<p><b>6.</b> Replaced spaces with dashes: " . str_replace(' ', '-', $input) . "</p>");
echo("</div>");
echo("<br><a href='strings_fun.php'>🔄 Try Again</a>");
}
include('includes/footer.php');
?>
</body>
</html>