What are the advantages of using filter_var with FILTER_VALIDATE_EMAIL over manual email validation in PHP scripts?

When validating email addresses in PHP scripts, using filter_var with FILTER_VALIDATE_EMAIL is advantageous over manual email validation because it provides a built-in and standardized way to validate email addresses according to the official RFC 822 specification. This function handles edge cases and complex email formats more effectively than manual validation, reducing the likelihood of errors in the validation process.

$email = "example@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Email is valid.";
} else {
    echo "Email is invalid.";
}