How can PHP be used to validate form input, such as email addresses?

To validate form input such as email addresses in PHP, you can use the built-in filter_var function with the FILTER_VALIDATE_EMAIL filter. This function will check if the input is a valid email address format. If the input is not valid, you can display an error message to the user.

$email = $_POST['email'];

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Invalid email format";
} else {
    echo "Email is valid";
}