<?php
include('includes/header.php');
?>
<h1>Orlando's Mad Libs Game</h1>
<form method="post">
Enter a name: <input type="text" name="name" required><br><br>
Enter a place: <input type="text" name="place" required><br><br>
Enter a noun: <input type="text" name="noun" required><br><br>
Enter a verb: <input type="text" name="verb" required><br><br>
Enter an adjective: <input type="text" name="adjective" required><br><br>
<input type="submit" value="Create Story">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars(trim($_POST['name']));
$place = htmlspecialchars(trim($_POST['place']));
$noun = htmlspecialchars(trim($_POST['noun']));
$verb = htmlspecialchars(trim($_POST['verb']));
$adjective = htmlspecialchars(trim($_POST['adjective']));
$name = ucwords($name);
$place = ucwords($place);
$noun = strtolower($noun);
$verb = strtolower($verb);
$adjective = strtolower($adjective);
$wordsArray = [' ', "$name $place $noun $verb $adjective"];
$wordsArray = explode(" ", $wordsArray[1]);
$story_template = "Once upon a time, {name} went to {place}.
There, they saw a {adjective} {noun} that could {verb}. <br>
Amazed, {name} decided to {verb} with the {noun} and had the time of their life!";
$story = str_replace(
["{name}", "{place}", "{noun}", "{verb}", "{adjective}"],
["$name", "$place", "$noun", "$verb", "$adjective"],
$story_template
);
echo "<h2>Your Mad Libs Story:</h2>";
echo "<p>$story</p><br>";
echo("<pre>");
echo("Words you entered: <br>");
print_r($wordsArray);
echo("</pre>");
}
?>
<?php
include('includes/footer.php');
?>