How can the PHP filter_var function be utilized for validating email addresses?
When validating email addresses in PHP, the filter_var function can be utilized with the FILTER_VALIDATE_EMAIL flag. This function will check if the provided email address is in a valid format according to RFC 822 and RFC 5322 standards. By using filter_var with FILTER_VALIDATE_EMAIL, we can easily validate email addresses in our PHP applications.
$email = "example@example.com";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Valid email address";
} else {
echo "Invalid email address";
}