<?php
function isValidEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}
$testEmail = "[email protected]";
if (isValidEmail($testEmail)) {
echo "$testEmail is a valid email address.";
} else {
echo "$testEmail is not a valid email address.";
}
?>
- The script defines a function
isValidEmail
that uses thefilter_var
function with theFILTER_VALIDATE_EMAIL
filter to check if a given string is a valid email address. - The script then calls the function with a sample email address (
$testEmail
) and prints the result.