How can the use of substr_count and strpos functions help in validating email addresses in PHP?

When validating email addresses in PHP, we can use the substr_count function to check for the presence of the "@" symbol, which is a required component of a valid email address. We can also use the strpos function to verify that the "@" symbol is not at the beginning or end of the email address, as well as to ensure that there is at least one "." symbol following the "@" symbol in the domain part of the email address.

$email = "example@example.com";

if (substr_count($email, "@") == 1 && strpos($email, "@") > 0 && strpos($email, ".") > strpos($email, "@")) {
    echo "Valid email address";
} else {
    echo "Invalid email address";
}