What are the recommended alternatives to the deprecated eregi() function in PHP for email validation?

The eregi() function in PHP has been deprecated since PHP 5.3 and removed in PHP 7. Instead of using eregi() for email validation, it is recommended to use the preg_match() function with a regular expression pattern to validate email addresses. This allows for more flexibility and control over the validation process.

$email = "example@example.com";

if (preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/", $email)) {
    echo "Email is valid";
} else {
    echo "Email is invalid";
}