How can the filter_var() function with FILTER_VALIDATE_EMAIL be used for email validation in PHP?
To validate an email address in PHP, you can use the filter_var() function with the FILTER_VALIDATE_EMAIL flag. This function will check if the provided email address is in a valid format according to RFC 822. If the email address is valid, the function will return the email address. If not, it will return false.
$email = "example@example.com";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Email address is valid.";
} else {
echo "Invalid email address.";
}