In PHP, what are some common methods for sanitizing and validating user input from forms?

When working with user input from forms in PHP, it is important to sanitize and validate the data to prevent security vulnerabilities and ensure data integrity. Common methods for sanitizing user input include using functions like htmlspecialchars() to prevent XSS attacks, and validating input can be done using functions like filter_var() with appropriate filters. By combining these methods, you can ensure that the data submitted through forms is safe and meets the expected format.

// Sanitize user input
$sanitized_input = htmlspecialchars($_POST['user_input']);

// Validate user input
if (filter_var($sanitized_input, FILTER_VALIDATE_EMAIL)) {
    // Input is a valid email address
} else {
    // Input is not a valid email address
}