What are the advantages of using filter_var() over ereg for email validation in PHP?

Using filter_var() for email validation in PHP is advantageous over ereg because filter_var() is a built-in function specifically designed for validating and sanitizing data, including email addresses. It is more efficient, secure, and easier to use compared to the now deprecated ereg function. Filter_var() provides a simple and reliable way to validate email addresses without the need for complex regular expressions.

$email = "example@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}