How can PHP be used to dynamically generate pages based on user input?
To dynamically generate pages based on user input in PHP, you can use forms to collect user input, process the input using PHP, and then generate the desired content based on the input provided by the user.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_input = $_POST['user_input'];
// Process user input and generate dynamic content
$dynamic_content = "Hello, " . $user_input . "! Welcome to our website.";
// Display the dynamically generated content
echo $dynamic_content;
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="user_input">Enter your name:</label>
<input type="text" name="user_input">
<button type="submit">Submit</button>
</form>