<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Manipulation Form</title>
</head>
<body>
<h1>Brian String Manipulation Form</h1>
<form method="post" action="">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br><br>
<label for="sentence">Sentence:</label>
<textarea id="sentence" name="sentence" required></textarea>
<br><br>
<input type="submit" value="Submit">
</form>
<?php
include('includes/header.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Gather values
$name = $_POST['name'];
$sentence = $_POST['sentence'];
// Perform string operations
$name_length = strlen($name);
$sentence_length = strlen($sentence);
$name_upper = strtoupper($name);
$name_lower = strtolower($name);
$replaced_sentence = str_replace("fun", "awesome", $sentence);
$starts_with = strpos($sentence, "Learning") === 0;
$position_of_string = strpos($sentence, "string");
$count_n = substr_count($sentence, "n");
// Display results
echo "<h2>Results</h2>";
echo "<p><strong>Name:</strong> $name</p>";
echo "<p>Length: $name_length</p>";
echo "<p>Uppercase: $name_upper</p>";
echo "<p>Lowercase: $name_lower</p>";
echo "<p><strong>Sentence:</strong> $sentence</p>";
echo "<p>Length: $sentence_length</p>";
echo "<p>Replaced: $replaced_sentence</p>";
echo "<p>Starts with 'Learning': " . ($starts_with ? 'True' : 'False') . "</p>";
echo "<p>Position of 'string': " . ($position_of_string !== false ? $position_of_string : 'Not found') . "</p>";
echo "<p>Count of 'n': $count_n</p>";
}
include('includes/footer.php');
?>
</body>
</html>