What are the advantages of using preg_match over ereg() for email validation in PHP, and how can this improve the accuracy of checking email addresses?

Using preg_match over ereg() for email validation in PHP is advantageous because preg_match is faster and more efficient than ereg(). Additionally, preg_match allows for more flexible and accurate pattern matching, which is crucial for accurately checking email addresses. By using preg_match, you can improve the accuracy of email validation and ensure that only valid email addresses are accepted.

$email = "example@example.com";

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