How can PHP be used to create and link HTML files based on form input?
To create and link HTML files based on form input using PHP, you can use the $_POST superglobal to retrieve the form data, create a new HTML file with the form input as content, and then provide a link to this newly created file for the user to access.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input = $_POST['input']; // Retrieve form input
$file = fopen("newfile.html", "w"); // Create a new HTML file
fwrite($file, $input); // Write form input to the file
fclose($file); // Close the file
echo "File created successfully. <a href='newfile.html'>Click here to view</a>"; // Provide link to the newly created file
}
?>
Keywords
Related Questions
- What potential pitfalls should be avoided when building a search field in PHP that interacts with a database?
- How can a PHP developer loop through an array and perform an insert for each element into a database?
- What are the advantages of using the PHP-Mailer Class over the standard PHP mail function, especially in terms of RFC compliance and communication with SMTP servers?