What are the advantages and disadvantages of using PHP to store user input in a text file for a website?

Storing user input in a text file using PHP can be advantageous as it is a simple and straightforward way to save data without the need for a database. However, it can be less secure and scalable compared to using a database. It is important to properly sanitize and validate user input to prevent security vulnerabilities.

<?php
// Get user input from a form
$user_input = $_POST['user_input'];

// Sanitize and validate user input
$user_input = htmlspecialchars($user_input);
$user_input = trim($user_input);

// Save user input to a text file
$file = 'user_input.txt';
file_put_contents($file, $user_input, FILE_APPEND);
?>