What are some potential security vulnerabilities that can arise from not properly sanitizing and validating input in PHP?

Failure to properly sanitize and validate input in PHP can lead to security vulnerabilities such as SQL injection, cross-site scripting (XSS), and remote code execution. To mitigate these risks, it is important to sanitize input by removing any potentially harmful characters and validate input to ensure it meets the expected format and type.

// Sanitize input by removing potentially harmful characters
$input = $_POST['input'];
$sanitized_input = filter_var($input, FILTER_SANITIZE_STRING);

// Validate input to ensure it meets the expected format and type
if (filter_var($sanitized_input, FILTER_VALIDATE_EMAIL)) {
    // Input is a valid email address
} else {
    // Input is not a valid email address
}